Language of x86 processor family

Size: px
Start display at page:

Download "Language of x86 processor family"

Transcription

1 Assembler lecture 2 S.Šimoňák, DCI FEEI TU of Košice Language of x86 processor family Assembler commands: instructions (processor, instructions of machine language) directives (compiler translation control, not a machine language instructions generation) macros (group of commands, compilation-time substitution expansion) Command format: [label] mnemonics [operands] [;comment] label (separated by : from mnemonics, not in case of directives) repeat: inc count ;increase 'count' 1 CR EQU 0DH ;carriage return Data objects allocation HLL indirectly, by specifying variable type (int sum;) except the space allocation, a way of interpretation given too (unsigned s1 vs. int s2; 4B both) assembler allocation, and initialisation respectively (not interpretation), format: [variable] directive init.value [, init.value] allocation directives (with initialization): DB (define byte, 1B), DW (define word, 2B), DD (define doubleword, 4B), DQ (define quadword, 8B), DT (def. ten bytes, 10B)

2 sorted DB 'y' (the same: sorted DB 79H) value DW (6247H, Little endian: 47, 62) expr1 DW 7*25 (initialisation by expression) range of values (signed and unsigned numbers) allocation directives (without initialization) - RESB (reserve byte, 1B), RESW (2B), RESD (4B), RESQ (8B), REST (10B) buffer resw 100 (array of 100 words) Multiple definitions continuous memory block allocation for sequence of definitions message DB 'BYE', 0DH, 0AH directive TIMES multiple initialization to the same value (arrays) marks TIMES 8 DW 0 Operands most instructions require operands addressing a way of specifying operand location basic operand types (details later): register (register CPU contains data, speed) EAX, EBX

3 immediate (datum directly within instruction code segment) AL, 65 (source immediate, dest - register) memory (effective address (offset): part of instruction direct, in register indirect) address vs. value (NASM: EBX, table, resp. EBX, [table]) table TIMES 20 DD 0... [table], 'A' ; direct memory addressing EBX, table ; indirect memory addressing [EBX], 100 ; table[0] = 100 (size of data?) add EBX, 4 ; table item 4B (DD) [EBX], 99 ; table[1] = 99 implicit operand stc, clc, pusha, popa,... Basic instructions of Pentium processor language reference guide (e.g. [2, 3]) Data transfer instructions instruction MOV (copy), usage rules (src unchanged, same operand size) syntax dst, src (dst src)

4 operand combinations (R register, M memory, I - immediate) R, R R, M R, I ( EAX, 3) M, R M, I M, M combination not allowed! (explicit) data size specification (BYTE, WORD, DWORD, QWORD, TBYTE) [EBX], 100 BYTE [EBX], 100 WORD [EBX], 100 ; data size not clear ; write 1B ; write 2B instruction XCHG (exchange) operand exchange, syntax xchg dst, src (dst src) rules (both operands in memory not allowed) exchange without auxiliary register (sorting, little/big endian) ECX, EAX vs. xchg EAX, EDX EAX, EDX EDX, ECX instruction XLAT (translate) character translation, syntax xlat usage input: EBX table starting address, AL index output: AL (byte from the resulting address)

5 Arithmetic operations instructions INC and DEC increasing/decreasing operand value (8, 16, 32-bit; register/memory) by 1, syntax inc dst dec dst count DW 0 value DB 25.code inc [count] EBX,count inc [EBX] inc WORD [EBX] (inc EBX) (dec DL) ; OK (type 'count' known) ; ambiguity ; OK instruction ADD addition 8, 16, 32-bit operands, syntax add dst, src (dst dst + src) rules (like MOV instruction) INC vs. ADD (preferred INC less memory) inc EAX vs. add EAX, 1 instruction SUB subtraction 8, 16, 32-bit operands, syntax sub dst, src (dst dst - src) instruction CMP similarly like SUB, but result not stored ('dst' unchanged, setting flags) typical usage conditional jumps

6 Jumps and iterations unconditional jump JMP passing the control to label jmp label (EIP label) conditional jumps program execution transferred to label (at satisfied condition) j<cond> label cmp AL, 0DH je CD_received ; jump on equal register FLAGS (ZF = 1 when CMP operands are equal) not all the instructions affect flags (MOV) conditions simple test of flag value (jz, jnz, jc, jnc, ) more complex conditions (jg, jl, jge, jle, ) iterations can also be realized with jumps direct iterations support LOOP syntax loop label operation (ECX counter): ECX = ECX 1 if ECX 0 then EIP label

7 Logical operations instructions AND, OR, XOR, NOT syntax and dst, src not dst (or, xor) (unary operator) truth tables and 0 1 or 0 1 xor operations AND, OR, XOR, NOT [1] logical operations usage

8 instruction TEST if operand modification is a problem performs bit operation AND (like and instruction), sets flags in the same way, without operand modification test AL, 01H ;can be used in previous example instead of: and AL, 01H shifts SHL (shift left) one bit left (CF MSB, LSB 0) SHR (shift right) one bit right (CF LSB, MSB 0) syntax (shl, shr), dst (8, 16, 32-bit M/R) shl dst, count shl dst, CL ; direct shift specification(0-31) ; indirect, in CL register usage of shift operations (LSb, CF)

9 rotations lost of bits when shifts are used sometimes unwanted rotations without CF instructions ROL, ROR last bit shifted out captured in CF syntax (ROL, ROR) rol dst, count rol dst, CL ROL rotation left; bits falling off on the left placed on the right side (D i+1 D i, LSB MSB, CF MSB) ROR rotation right; bits falling off on the right placed on the left side (D i D i+1, MSB LSB, CF LSB) rotations through CF instructions RCL, RCR CF involved in rotation process, syntax (like ROL, ROR) RCL rotation left; bit rotated out goes into CF, CF enters from right side (D i+1 D i, CF MSB, LSB CF) RCR rotation right; bit rotated out goes into CF, CF enters from left side (D i D i+1, CF LSB, MSB CF) using rotations with multiword shifts (64-bit, EDX:EAX by 1 bit right) shr EDX, 1 rcr EAX, 1

10 Constants and Macros NASM offers several possibilities, we will discuss 3 directives: directive EQU syntax name EQU expr usage assigning the value of 'expr' to the 'name' (where expr can be evaluated in compile time) advantages: program readability, multiple constant occurrence changing at one place values assigned can not be changed within a source module directive %assign - like EQU (defining numerical constants), but redefinition possible %assign i j+1 <code fragment> %assign i j+2 directive %define - numerical and string constants, redefinition possible %define X1 [EBP+4] <code fragment> %define X1 [EBP+20]

11 Macros block of text represented by name when name occurs in program replaced by the corresponding block (macro expansion) %macro macro_name <macro body> %endmacro para_count calling the macro name of macro with corresponding parameters macros without parameters definition: calling macro: after macro expansion: %macro multeax_by_ sal EAX, 4 EAX, 27 EAX, 27 %endmacro multeax_by_16 sal EAX, macros with parameters - generalization of macro in macro body parameters accessed by the order (%1) definition: calling macro: after macro expansion: %macro mult_by_ sal %1, 4 mult_by_16 DL sal DL, 4 %endmacro......

12 Assembly programming assembling - translation of AL program into machine code linking - linking the machine code and data in object files and libraries executable file debugging Input and output non-existence of standard mechanism in AL programming (system dependent) solutions direct HW access operating system services standard libraries of HLL within our course used [2] sub-programs for simplifying basic I/O operations (C library used) print_int (integer value in EAX) print_char (ASCII in AL) print_string (address in EAX, null terminator) print_nl (new line) read_int (stored in EAX) read_char (ASCII into EAX) register contents preserved (read* - modify EAX) usage %include asm_io.inc calling operations (call)

13 Debugging method used within course [2] displaying the state of computer (without modification) macros defined in asm_io.inc operations: dump_regs (HEX dump of registers, FLAGS, argument dump number) dump_mem (HEX/ASCII dump of memory, arg1 dump number, arg2 address, arg3 number of 16B blocks) dump_stack (stack content, arg1 dump number, arg2 # doublewords under EBP, arg3 # doublewords over EBP) dump_math (values in FPU registers, argument dump number) C language and AL programming programs seldom written in pure AL (HLL benefits...) more often combination with HLL (e.g. C) critical parts in AL (speed, HW access,...) start of (AL) program from C-driver, motivation: switch to protected mode (SR initialized, tables in memory) access to standard C-library (I/O, )

14 Sample program driver in C (driver.c) int main() { int ret_status; ret_status = asm_main(); return ret_status; } assembly program segment.data (initialized, strings terminated by 0) segment.bss (non-initialized, if required, e.g. stack) segment.text (program code) _asm_main (C-calling convention; all C symbols (functions, global variables) prefix '_' (DOS/Win),...) global _asm_main (creating global label, accessible from all modules) compilation (MinGW/DevCPP) assembler nasm -f win32 -d COFF_TYPE asm_io.asm (asm_io.obj) assembler nasm -f win32 first.asm (first.obj) driver.c gcc -c driver.c (driver.o) linker gcc -o first driver.o first.obj asm_io.obj (gcc calls linker with correct parameters, first.exe) object formats of other C-compilers [3] Study literature: [1] Dandamudi,S.,P.: Introduction to Assembly Language Programming, Springer Science+Business Media, Inc., [2] Carter, A., P.: PC Assembly Language, 2006, [3] NASM - The Netwide Assembler, The NASM Development Team, 2007,

15 ; Objective: HEX value of character entered. ; Input: Char from keyboard. ; Output: Prints ASCII code of char in HEX. %include "asm_io.inc" segment.data char_prompt db "Please input a character: ",0 out_msg1 db "The ASCII code of '",0 out_msg2 db "' in HEX is ",0 segment.text global _asm_main _asm_main: enter 0,0 pusha call call call EAX, char_prompt print_string read_char EBX, EAX print_nl print_digit: cmp AL,9 jg A_to_F ; translation A F add AL,'0' ; translation 0 9 jmp skip A_to_F: add AL,'A'-10 skip: call print_char AL,AH and AL,0FH loop print_digit popa EAX, 0 leave ret call call call shr EAX, out_msg1 print_string EAX, EBX print_char EAX, out_msg2 print_string EAX, EBX AH,AL AL,4 ECX,2

Assembly basics CS 2XA3. Term I, 2017/18

Assembly basics CS 2XA3. Term I, 2017/18 Assembly basics CS 2XA3 Term I, 2017/18 Outline What is Assembly Language? Assemblers NASM Program structure I/O First program Compiling Linking What is Assembly Language? In a high level language (HLL),

More information

Basic Assembly. Ned Nedialkov. McMaster University Canada. SE 3F03 January 2014

Basic Assembly. Ned Nedialkov. McMaster University Canada. SE 3F03 January 2014 Basic Assembly Ned Nedialkov McMaster University Canada SE 3F03 January 2014 Outline Assemblers Basic instructions Program structure I/O First program Compiling Linking c 2013 14 Ned Nedialkov 2/9 Assemblers

More information

Assembler lecture 4 S.Šimoňák, DCI FEEI TU of Košice

Assembler lecture 4 S.Šimoňák, DCI FEEI TU of Košice Assembler lecture 4 S.Šimoňák, DCI FEEI TU of Košice Addressing data access specification arrays - specification and manipulation impacts of addressing to performance Processor architecture CISC (more

More information

Assembler lecture 5 S.Šimoňák, DCI FEEI TU of Košice

Assembler lecture 5 S.Šimoňák, DCI FEEI TU of Košice Assembler lecture 5 S.Šimoňák, DCI FEEI TU of Košice Jumps and iterations conditional and unconditional jumps iterations (loop) implementation of HLL control structures Unconditional jump unconditional

More information

Introduction to 8086 Assembly

Introduction to 8086 Assembly Introduction to 8086 Assembly Lecture 8 Bit Operations Clock cycle & instruction timing http://www.newagepublishers.com/samplechapter/000495.pdf Clock cycle & instruction timing See 8086: http://www.oocities.org/mc_introtocomputers/instruction_timing.pdf

More information

Stack, subprograms. procedures and modular programming role of stack while using procedures stack implementation (Pentium)

Stack, subprograms. procedures and modular programming role of stack while using procedures stack implementation (Pentium) Assembler lecture 3 S.Šimoňák, DCI FEEI TU of Košice Stack, subprograms procedures and modular programming role of stack while using procedures stack implementation (Pentium) Stack LIFO data structure,

More information

Overview of Assembly Language

Overview of Assembly Language Overview of Assembly Language Chapter 9 S. Dandamudi Outline Assembly language statements Data allocation Where are the operands? Addressing modes» Register» Immediate» Direct» Indirect Data transfer instructions

More information

Introduction to 8086 Assembly

Introduction to 8086 Assembly Introduction to 8086 Assembly Lecture 6 Working with memory Why using memory? Registers are limited in number and size Program data Program code etc. The data segment dd 1234 dw 13 db -123 The data segment

More information

Logical and bit operations

Logical and bit operations Assembler lecture 6 S.Šimoňák, DCI FEEI TU of Košice Logical and bit operations instructions performing logical operations, shifts and rotations logical expressions and bit manipulations strings Logical

More information

Subprograms: Arguments

Subprograms: Arguments Subprograms: Arguments ICS312 Machine-Level and Systems Programming Henri Casanova (henric@hawaii.edu) Activation Records The stack is useful to store and rieve urn addresses, transparently managed via

More information

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

X86 Addressing Modes Chapter 3 Review: Instructions to Recognize X86 Addressing Modes Chapter 3" Review: Instructions to Recognize" 1 Arithmetic Instructions (1)! Two Operand Instructions" ADD Dest, Src Dest = Dest + Src SUB Dest, Src Dest = Dest - Src MUL Dest, Src

More information

Logical and Bit Operations. Chapter 8 S. Dandamudi

Logical and Bit Operations. Chapter 8 S. Dandamudi Logical and Bit Operations Chapter 8 S. Dandamudi Outline Logical instructions AND OR XOR NOT TEST Shift instructions Logical shift instructions Arithmetic shift instructions Rotate instructions Rotate

More information

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs CSC 2400: Computer Systems Towards the Hardware: Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32)

More information

SOEN228, Winter Revision 1.2 Date: October 25,

SOEN228, Winter Revision 1.2 Date: October 25, SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003 1 Contents Flags Mnemonics Basic I/O Exercises Overview of sample programs 2 Flag Register The flag register stores the condition flags that retain

More information

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10] The following pages contain references for use during the exam: tables containing the x86 instruction set (covered so far) and condition codes. You do not need to submit these pages when you finish your

More information

CSC 8400: Computer Systems. Machine-Level Representation of Programs

CSC 8400: Computer Systems. Machine-Level Representation of Programs CSC 8400: Computer Systems Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32) 1 Compilation Stages

More information

Instructions moving data

Instructions moving data do not affect flags. Instructions moving data mov register/mem, register/mem/number (move data) The difference between the value and the address of a variable mov al,sum; value 56h al mov ebx,offset Sum;

More information

Subprograms: Local Variables

Subprograms: Local Variables Subprograms: Local Variables ICS312 Machine-Level and Systems Programming Henri Casanova (henric@hawaii.edu) Local Variables in Subprograms In all the examples we have seen so far, the subprograms were

More information

PC Assembly Language. Paul A. Carter

PC Assembly Language. Paul A. Carter PC Assembly Language Paul A. Carter January 6, 2000 c 2000 Paul Carter All Rights Reserved Contents Preface v 1 Introduction 1 1.1 Number Systems......................... 1 1.1.1 Decmial..........................

More information

Defining and Using Simple Data Types

Defining and Using Simple Data Types 85 CHAPTER 4 Defining and Using Simple Data Types This chapter covers the concepts essential for working with simple data types in assembly-language programs The first section shows how to declare integer

More information

Lecture (08) x86 programming 7

Lecture (08) x86 programming 7 Lecture (08) x86 programming 7 By: Dr. Ahmed ElShafee 1 Conditional jump: Conditional jumps are executed only if the specified conditions are true. Usually the condition specified by a conditional jump

More information

Arithmetic and Logic Instructions And Programs

Arithmetic and Logic Instructions And Programs Dec Hex Bin 3 3 00000011 ORG ; FOUR Arithmetic and Logic Instructions And Programs OBJECTIVES this chapter enables the student to: Demonstrate how 8-bit and 16-bit unsigned numbers are added in the x86.

More information

Overview: 1. Overview: 2

Overview: 1. Overview: 2 1: TITLE Binary equivalent of characters BINCHAR.ASM 3: Objective: To print the binary equivalent of 4: ASCII character code. 5: Input: Requests a character from keyboard. 6: Output: Prints the ASCII code

More information

Computer Architecture and System Programming Laboratory. TA Session 3

Computer Architecture and System Programming Laboratory. TA Session 3 Computer Architecture and System Programming Laboratory TA Session 3 Stack - LIFO word-size data structure STACK is temporary storage memory area register points on top of stack (by default, it is highest

More information

Logic Instructions. Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Segment 4A

Logic Instructions. Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Segment 4A Segment 4A Logic Instructions Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Course Instructor Mohammed Abdul kader Lecturer, EEE, IIUC Basic

More information

CS-202 Microprocessor and Assembly Language

CS-202 Microprocessor and Assembly Language CS-202 Microprocessor and Assembly Language Lecture 2 Introduction to 8086 Assembly Language Dr Hashim Ali Spring - 2019 Department of Computer Science and Engineering HITEC University Taxila!1 Lecture

More information

Computer Architecture and Assembly Language. Practical Session 3

Computer Architecture and Assembly Language. Practical Session 3 Computer Architecture and Assembly Language Practical Session 3 Advanced Instructions division DIV r/m - unsigned integer division IDIV r/m - signed integer division Dividend Divisor Quotient Remainder

More information

PC Assembly Language. Paul A. Carter

PC Assembly Language. Paul A. Carter PC Assembly Language Paul A. Carter August 25, 2002 Copyright c 2001, 2002 by Paul Carter This may be reproduced and distributed in its entirety (including this authorship, copyright and permission notice),

More information

Kingdom of Saudi Arabia Ministry of Higher Education. Taif University. Faculty of Computers & Information Systems

Kingdom of Saudi Arabia Ministry of Higher Education. Taif University. Faculty of Computers & Information Systems Kingdom of Saudi Arabia Ministry of Higher Education Taif University Faculty of Computers & Information Systems المملكة العربية السعودية وزارة التعليم العالي جامعة الطاي ف آلية الحاسبات ونظم المعلومات

More information

Practical Malware Analysis

Practical Malware Analysis Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the

More information

Ethical Hacking. Assembly Language Tutorial

Ethical Hacking. Assembly Language Tutorial Ethical Hacking Assembly Language Tutorial Number Systems Memory in a computer consists of numbers Computer memory does not store these numbers in decimal (base 10) Because it greatly simplifies the hardware,

More information

Basic Assembly SYSC-3006

Basic Assembly SYSC-3006 Basic Assembly Program Development Problem: convert ideas into executing program (binary image in memory) Program Development Process: tools to provide people-friendly way to do it. Tool chain: 1. Programming

More information

Lecture 2 Assembly Language

Lecture 2 Assembly Language Lecture 2 Assembly Language Computer and Network Security 9th of October 2017 Computer Science and Engineering Department CSE Dep, ACS, UPB Lecture 2, Assembly Language 1/37 Recap: Explorations Tools assembly

More information

CSE P 501 Compilers. x86 Lite for Compiler Writers Hal Perkins Autumn /25/ Hal Perkins & UW CSE J-1

CSE P 501 Compilers. x86 Lite for Compiler Writers Hal Perkins Autumn /25/ Hal Perkins & UW CSE J-1 CSE P 501 Compilers x86 Lite for Compiler Writers Hal Perkins Autumn 2011 10/25/2011 2002-11 Hal Perkins & UW CSE J-1 Agenda Learn/review x86 architecture Core 32-bit part only for now Ignore crufty, backward-compatible

More information

3.1 DATA MOVEMENT INSTRUCTIONS 45

3.1 DATA MOVEMENT INSTRUCTIONS 45 3.1.1 General-Purpose Data Movement s 45 3.1.2 Stack Manipulation... 46 3.1.3 Type Conversion... 48 3.2.1 Addition and Subtraction... 51 3.1 DATA MOVEMENT INSTRUCTIONS 45 MOV (Move) transfers a byte, word,

More information

Assembly Language Programming

Assembly Language Programming Assembly Language Programming Integer Constants Optional leading + or sign Binary, decimal, hexadecimal, or octal digits Common radix characters: h hexadecimal d decimal b binary r encoded real q/o - octal

More information

mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Back to Conditional Jumps Review sub eax, 10 jz there xxx xxx there:yyy yyy Review cmp eax, 10 jz

More information

ECOM Computer Organization and Assembly Language. Computer Engineering Department CHAPTER 7. Integer Arithmetic

ECOM Computer Organization and Assembly Language. Computer Engineering Department CHAPTER 7. Integer Arithmetic ECOM 2325 Computer Organization and Assembly Language Computer Engineering Department CHAPTER 7 Integer Arithmetic Presentation Outline Shift and Rotate Instructions Shift and Rotate Applications Multiplication

More information

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313) Philadelphia University Faculty of Engineering Marking Scheme Examination Paper Department of CE Module: Microprocessors (630313) Final Exam Second Semester Date: 02/06/2018 Section 1 Weighting 40% of

More information

Chapter 12. Selected Pentium Instructions

Chapter 12. Selected Pentium Instructions Chapter 12 Selected Pentium Instructions 1 2 Chapter 12 12 1 Carry flag indicates out-of-range error for unsigned operations. Chapter 12 3 12 2 Overflow flag indicates out-of-range error for signed operations.

More information

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS 1. Object of laboratory The x86 microprocessor family has a large variety of instructions that allow instruction flow control. We have 4 categories: jump,

More information

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string.

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string. 1 od 5 17. 12. 2017 23:53 (https://github.com/schweigi/assembler-simulator) Introduction This simulator provides a simplified assembler syntax (based on NASM (http://www.nasm.us)) and is simulating a x86

More information

Week /8086 Microprocessor Programming I

Week /8086 Microprocessor Programming I Week 4 8088/8086 Microprocessor Programming I Example. The PC Typewriter Write an 80x86 program to input keystrokes from the PC s keyboard and display the characters on the system monitor. Pressing any

More information

Introduction to 8086 Assembly

Introduction to 8086 Assembly Introduction to 8086 Assembly Lecture 7 Multiplication and Division Multiplication commands: mul and imul mul source (source: register/memory) Unsigned Integer Multiplication (mul) mul src (src: register/memory)

More information

Program Exploitation Intro

Program Exploitation Intro Program Exploitation Intro x86 Assembly 04//2018 Security 1 Univeristà Ca Foscari, Venezia What is Program Exploitation "Making a program do something unexpected and not planned" The right bugs can be

More information

Week /8086 Microprocessor Programming

Week /8086 Microprocessor Programming Week 5 8088/8086 Microprocessor Programming Multiplication and Division Multiplication Multiplicant Operand Result (MUL or IMUL) (Multiplier) Byte * Byte AL Register or memory Word * Word AX Register or

More information

Reverse Engineering Low Level Software. CS5375 Software Reverse Engineering Dr. Jaime C. Acosta

Reverse Engineering Low Level Software. CS5375 Software Reverse Engineering Dr. Jaime C. Acosta 1 Reverse Engineering Low Level Software CS5375 Software Reverse Engineering Dr. Jaime C. Acosta Machine code 2 3 Machine code Assembly compile Machine Code disassemble 4 Machine code Assembly compile

More information

22 Assembly Language for Intel-Based Computers, 4th Edition. 3. Each edge is a transition from one state to another, caused by some input.

22 Assembly Language for Intel-Based Computers, 4th Edition. 3. Each edge is a transition from one state to another, caused by some input. 22 Assembly Language for Intel-Based Computers, 4th Edition 6.6 Application: Finite-State Machines 1. A directed graph (also known as a diagraph). 2. Each node is a state. 3. Each edge is a transition

More information

Q1: Multiple choice / 20 Q2: Protected mode memory accesses

Q1: Multiple choice / 20 Q2: Protected mode memory accesses 16.317: Microprocessor-Based Systems I Summer 2012 Exam 2 August 1, 2012 Name: ID #: For this exam, you may use a calculator and one 8.5 x 11 double-sided page of notes. All other electronic devices (e.g.,

More information

An Introduction to x86 ASM

An Introduction to x86 ASM An Introduction to x86 ASM Malware Analysis Seminar Meeting 1 Cody Cutler, Anton Burtsev Registers General purpose EAX, EBX, ECX, EDX ESI, EDI (index registers, but used as general in 32-bit protected

More information

Process Layout and Function Calls

Process Layout and Function Calls Process Layout and Function Calls CS 6 Spring 07 / 8 Process Layout in Memory Stack grows towards decreasing addresses. is initialized at run-time. Heap grow towards increasing addresses. is initialized

More information

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution 1. (40 points) Write the following subroutine in x86 assembly: Recall that: int f(int v1, int v2, int v3) { int x = v1 + v2; urn (x + v3) * (x v3); Subroutine arguments are passed on the stack, and can

More information

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated CNIT 127: Exploit Development Ch 1: Before you begin Updated 1-14-16 Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend, such as Denial

More information

CMSC 313 Lecture 07. Short vs Near Jumps Logical (bit manipulation) Instructions AND, OR, NOT, SHL, SHR, SAL, SAR, ROL, ROR, RCL, RCR

CMSC 313 Lecture 07. Short vs Near Jumps Logical (bit manipulation) Instructions AND, OR, NOT, SHL, SHR, SAL, SAR, ROL, ROR, RCL, RCR CMSC 313 Lecture 07 Short vs Near Jumps Logical (bit manipulation) Instructions AND, OR, NOT, SHL, SHR, SAL, SAR, ROL, ROR, RCL, RCR More Arithmetic Instructions NEG, MUL, IMUL, DIV Indexed Addressing:

More information

Conditional Processing

Conditional Processing ١ Conditional Processing Computer Organization & Assembly Language Programming Dr Adnan Gutub aagutub at uqu.edu.sa Presentation Outline [Adapted from slides of Dr. Kip Irvine: Assembly Language for Intel-Based

More information

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans.

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans. INSTRUCTOR: ABDULMUTTALIB A H ALDOURI Conditional Jump Cond Unsigned Signed = JE : Jump Equal JE : Jump Equal ZF = 1 JZ : Jump Zero JZ : Jump Zero ZF = 1 JNZ : Jump Not Zero JNZ : Jump Not Zero ZF = 0

More information

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher Reverse Engineering II: Basics Gergely Erdélyi Senior Antivirus Researcher Agenda Very basics Intel x86 crash course Basics of C Binary Numbers Binary Numbers 1 Binary Numbers 1 0 1 1 Binary Numbers 1

More information

Second Part of the Course

Second Part of the Course CSC 2400: Computer Systems Towards the Hardware 1 Second Part of the Course Toward the hardware High-level language (C) assembly language machine language (IA-32) 2 High-Level Language g Make programming

More information

Introduction to 8086 Assembly

Introduction to 8086 Assembly Introduction to 8086 Assembly Lecture 5 Jump, Conditional Jump, Looping, Compare instructions Labels and jumping (the jmp instruction) mov eax, 1 add eax, eax jmp label1 xor eax, eax label1: sub eax, 303

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer About the Tutorial Assembly language is a low-level programming language for a computer or other programmable device specific to a particular computer architecture in contrast to most high-level programming

More information

Branching and Looping

Branching and Looping Branching and Looping Ray Seyfarth August 10, 2011 Branching and looping So far we have only written straight line code Conditional moves helped spice things up In addition conditional moves kept the pipeline

More information

Assembly Language: IA-32 Instructions

Assembly Language: IA-32 Instructions Assembly Language: IA-32 Instructions 1 Goals of this Lecture Help you learn how to: Manipulate data of various sizes Leverage more sophisticated addressing modes Use condition codes and jumps to change

More information

mith College Computer Science CSC231 Assembly Week #9 Spring 2017 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #9 Spring 2017 Dominique Thiébaut mith College Computer Science CSC231 Assembly Week #9 Spring 2017 Dominique Thiébaut dthiebaut@smith.edu 2 Videos to Watch at a Later Time https://www.youtube.com/watch?v=fdmzngwchdk https://www.youtube.com/watch?v=k2iz1qsx4cm

More information

COMPUTER ENGINEERING DEPARTMENT

COMPUTER ENGINEERING DEPARTMENT Page 1 of 11 COMPUTER ENGINEERING DEPARTMENT December 31, 2007 COE 205 COMPUTER ORGANIZATION & ASSEMBLY PROGRAMMING Major Exam II First Semester (071) Time: 7:00 PM-9:30 PM Student Name : KEY Student ID.

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 5

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 5 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 5 LAST TIME Began exploring x86-64 instruction set architecture 16 general-purpose registers Also: All registers are 64 bits wide rax-rdx are

More information

Reverse Engineering II: The Basics

Reverse Engineering II: The Basics Reverse Engineering II: The Basics Gergely Erdélyi Senior Manager, Anti-malware Research Protecting the irreplaceable f-secure.com Binary Numbers 1 0 1 1 - Nibble B 1 0 1 1 1 1 0 1 - Byte B D 1 0 1 1 1

More information

Basic Assembly Instructions

Basic Assembly Instructions Basic Assembly Instructions Ned Nedialkov McMaster University Canada SE 3F03 January 2013 Outline Multiplication Division FLAGS register Branch Instructions If statements Loop instructions 2/21 Multiplication

More information

CPS104 Recitation: Assembly Programming

CPS104 Recitation: Assembly Programming CPS104 Recitation: Assembly Programming Alexandru Duțu 1 Facts OS kernel and embedded software engineers use assembly for some parts of their code some OSes had their entire GUIs written in assembly in

More information

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012 19:211 Computer Architecture Lecture 10 Fall 20 Topics:Chapter 3 Assembly Language 3.2 Register Transfer 3. ALU 3.5 Assembly level Programming We are now familiar with high level programming languages

More information

Module 3 Instruction Set Architecture (ISA)

Module 3 Instruction Set Architecture (ISA) Module 3 Instruction Set Architecture (ISA) I S A L E V E L E L E M E N T S O F I N S T R U C T I O N S I N S T R U C T I O N S T Y P E S N U M B E R O F A D D R E S S E S R E G I S T E R S T Y P E S O

More information

ASSEMBLY - QUICK GUIDE ASSEMBLY - INTRODUCTION

ASSEMBLY - QUICK GUIDE ASSEMBLY - INTRODUCTION ASSEMBLY - QUICK GUIDE http://www.tutorialspoint.com/assembly_programming/assembly_quick_guide.htm Copyright tutorialspoint.com What is Assembly Language? ASSEMBLY - INTRODUCTION Each personal computer

More information

Machine Code and Assemblers November 6

Machine Code and Assemblers November 6 Machine Code and Assemblers November 6 CSC201 Section 002 Fall, 2000 Definitions Assembly time vs. link time vs. load time vs. run time.c file.asm file.obj file.exe file compiler assembler linker Running

More information

PRACTICAL WORKBOOK. Department of Computer Engineering University of Lahore. Designed and Compiled by : Engineer Zahid Muneer. Batch.

PRACTICAL WORKBOOK. Department of Computer Engineering University of Lahore. Designed and Compiled by : Engineer Zahid Muneer. Batch. PRACTICAL WORKBOOK Computer Architecture and Organization Name : Year : Batch : Roll No : Department of Computer Engineering University of Lahore Designed and Compiled by : Engineer Zahid Muneer 1 Contents

More information

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015 CS165 Computer Security Understanding low-level program execution Oct 1 st, 2015 A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns

More information

Basic Pentium Instructions. October 18

Basic Pentium Instructions. October 18 Basic Pentium Instructions October 18 CSC201 Section 002 Fall, 2000 The EFLAGS Register Bit 11 = Overflow Flag Bit 7 = Sign Flag Bit 6 = Zero Flag Bit 0 = Carry Flag "Sets the flags" means sets OF, ZF,

More information

Jump instructions. Unconditional jumps Direct jump. do not change flags. jmp label

Jump instructions. Unconditional jumps Direct jump. do not change flags. jmp label do not change flags Unconditional jumps Direct jump jmp label Jump instructions jmp Continue xor eax,eax Continue: xor ecx,ecx Machine code: 0040340A EB 02 0040340C 33 C0 0040340E 33 C9 displacement =

More information

CS61 Section Solutions 3

CS61 Section Solutions 3 CS61 Section Solutions 3 (Week of 10/1-10/5) 1. Assembly Operand Specifiers 2. Condition Codes 3. Jumps 4. Control Flow Loops 5. Procedure Calls 1. Assembly Operand Specifiers Q1 Operand Value %eax 0x104

More information

Basic Intel x86 Assembly Language Programming

Basic Intel x86 Assembly Language Programming 1 Basic Intel x86 Programming 2 Intel x86 Processor Family Processor Integer Width (bits) Physical Address (bits) Year Features 8086 16 20 1978 16-bit data I/O bus 8088 16 20 1979 8-bit data I/O bus Used

More information

Towards the Hardware"

Towards the Hardware CSC 2400: Computer Systems Towards the Hardware Chapter 2 Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32) 1 High-Level Language Make programming

More information

Lecture 9. INC and DEC. INC/DEC Examples ADD. ADD Examples SUB. INC adds one to a single operand DEC decrements one from a single operand

Lecture 9. INC and DEC. INC/DEC Examples ADD. ADD Examples SUB. INC adds one to a single operand DEC decrements one from a single operand Lecture 9 INC and DEC Arithmetic Operations Shift Instructions Next week s homework! INC adds one to a single operand DEC decrements one from a single operand INC destination DEC destination where destination

More information

Compiler construction. x86 architecture. This lecture. Lecture 6: Code generation for x86. x86: assembly for a real machine.

Compiler construction. x86 architecture. This lecture. Lecture 6: Code generation for x86. x86: assembly for a real machine. This lecture Compiler construction Lecture 6: Code generation for x86 Magnus Myreen Spring 2018 Chalmers University of Technology Gothenburg University x86 architecture s Some x86 instructions From LLVM

More information

Integer Arithmetic. Shift and rotate. Overview. Shift and Rotate Instructions

Integer Arithmetic. Shift and rotate. Overview. Shift and Rotate Instructions Overview Integer Arithmetic Shift and rotate instructions and their applications Multiplication and division instructions Extended addition and subtraction Computer Organization and Assembly Languages

More information

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB Lab # 9 Integer Arithmetic and Bit Manipulation April, 2014 1 Assembly Language LAB Bitwise

More information

CMSC 313 Lecture 05 [draft]

CMSC 313 Lecture 05 [draft] CMSC 313 Lecture 05 [draft] More on Conditional Jump Instructions Short Jumps vs Near Jumps Using Jump Instructions Logical (bit manipulation) Instructions AND, OR, NOT, SHL, SHR, SAL, SAR, ROL, ROR, RCL,

More information

EC 333 Microprocessor and Interfacing Techniques (3+1)

EC 333 Microprocessor and Interfacing Techniques (3+1) EC 333 Microprocessor and Interfacing Techniques (3+1) Lecture 6 8086/88 Microprocessor Programming (Arithmetic Instructions) Dr Hashim Ali Fall 2018 Department of Computer Science and Engineering HITEC

More information

UNIT II. 2 Marks. 2. List out the various register of IA- 32 Register structure. 3. Write about General purpose registers

UNIT II. 2 Marks. 2. List out the various register of IA- 32 Register structure. 3. Write about General purpose registers UNIT II The IA-32 Pentium Example: Registers and Addressing, IA-32 Instructions, IA-32 Assembly Language, Program Flow Control, Logic and Shift/Rotate Instructions, I/O Operations, Subroutines, Other Instructions,

More information

Ex : Write an ALP to evaluate x(y + z) where x = 10H, y = 20H and z = 30H and store the result in a memory location 54000H.

Ex : Write an ALP to evaluate x(y + z) where x = 10H, y = 20H and z = 30H and store the result in a memory location 54000H. Ex : Write an ALP to evaluate x(y + z) where x = 10H, y = 20H and z = 30H and store the result in a memory location 54000H. MOV AX, 5000H MOV DS, AX MOV AL, 20H MOV CL, 30H ADD AL, CL MOV CL, 10H MUL CL

More information

Lab 6: Conditional Processing

Lab 6: Conditional Processing COE 205 Lab Manual Lab 6: Conditional Processing Page 56 Lab 6: Conditional Processing Contents 6.1. Unconditional Jump 6.2. The Compare Instruction 6.3. Conditional Jump Instructions 6.4. Finding the

More information

8086 INSTRUCTION SET

8086 INSTRUCTION SET 8086 INSTRUCTION SET Complete 8086 instruction set Quick reference: AAA AAD AAM AAS ADC ADD AND CALL CBW CLC CLD CLI CMC CMP CMPSB CMPSW CWD DAA DAS DEC DIV HLT IDIV IMUL IN INC INT INTO I JA JAE JB JBE

More information

Assembly Language. Lecture 3 Assembly Fundamentals

Assembly Language. Lecture 3 Assembly Fundamentals Assembly Language Lecture 3 Assembly Fundamentals Ahmed Sallam Slides based on original lecture slides by Dr. Mahmoud Elgayyar General Concepts CPU Design, Instruction execution cycle IA-32 Processor Architecture

More information

16.317: Microprocessor Systems Design I Fall 2014

16.317: Microprocessor Systems Design I Fall 2014 16.317: Microprocessor Systems Design I Fall 2014 Exam 2 Solution 1. (16 points, 4 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

Computer Department Chapter 7. Created By: Eng. Ahmed M. Ayash Modified and Presented by: Eng. Eihab S. El-Radie. Chapter 7

Computer Department Chapter 7. Created By: Eng. Ahmed M. Ayash Modified and Presented by: Eng. Eihab S. El-Radie. Chapter 7 Islamic University Of Gaza Assembly Language Faculty of Engineering Discussion Computer Department Chapter 7 Created By: Eng. Ahmed M. Ayash Modified and Presented by: Eng. Eihab S. El-Radie Chapter 7

More information

Reverse Engineering II: The Basics

Reverse Engineering II: The Basics Reverse Engineering II: The Basics This document is only to be distributed to teachers and students of the Malware Analysis and Antivirus Technologies course and should only be used in accordance with

More information

Using MMX Instructions to Perform Simple Vector Operations

Using MMX Instructions to Perform Simple Vector Operations Using MMX Instructions to Perform Simple Vector Operations Information for Developers and ISVs From Intel Developer Services www.intel.com/ids Information in this document is provided in connection with

More information

Architecture and components of Computer System Execution of program instructions

Architecture and components of Computer System Execution of program instructions Execution of program instructions Microprocessor realizes each program instruction as the sequence of the following simple steps: 1. fetch next instruction or its part from memory and placing it in the

More information

Selection and Iteration. Chapter 7 S. Dandamudi

Selection and Iteration. Chapter 7 S. Dandamudi Selection and Iteration Chapter 7 S. Dandamudi Outline Unconditional jump Compare instruction Conditional jumps Single flags Unsigned comparisons Signed comparisons Loop instructions Implementing high-level

More information

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? exam on Wednesday today s material not on the exam 1 Assembly Assembly is programming

More information

Machine and Assembly Language Principles

Machine and Assembly Language Principles Machine and Assembly Language Principles Assembly language instruction is synonymous with a machine instruction. Therefore, need to understand machine instructions and on what they operate - the architecture.

More information

Lab 3. The Art of Assembly Language (II)

Lab 3. The Art of Assembly Language (II) Lab. The Art of Assembly Language (II) Dan Bruce, David Clark and Héctor D. Menéndez Department of Computer Science University College London October 2, 2017 License Creative Commons Share Alike Modified

More information

Summary: Direct Code Generation

Summary: Direct Code Generation Summary: Direct Code Generation 1 Direct Code Generation Code generation involves the generation of the target representation (object code) from the annotated parse tree (or Abstract Syntactic Tree, AST)

More information