Overview of Assembly Language

Size: px
Start display at page:

Download "Overview of Assembly Language"

Transcription

1 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 mov, xchg, and xlat PTR directive Overview of assembly language instructions Arithmetic Conditional Logical Shift Rotate Defining constants EQU and = directives Macros Illustrative examples S. Dandamudi Chapter 9: Page 2 1

2 Assembly Language Statements Three different classes Instructions» Tell CPU what to do» Executable instructions with an op-code Directives (or pseudo-ops)» Provide information to assembler on various aspects of the assembly process» Non-executable Do not generate machine language instructions Macros» A shorthand notation for a group of statements» A sophisticated text substitution mechanism with parameters S. Dandamudi Chapter 9: Page 3 Assembly Language Statements (cont d) Assembly language statement format: [label] mnemonic [operands] [;comment] Typically one statement per line Fields in [ ] are optional label serves two distinct purposes:» To label an instruction Can transfer program execution to the labeled instruction» To label an identifier or constant mnemonic identifies the operation (e.g., add, or) operands specify the data required by the operation» Executable instructions can have zero to three operands S. Dandamudi Chapter 9: Page 4 2

3 Assembly Language Statements (cont d) comments» Begin with a semicolon (;) and extend to the end of the line Examples repeat: inc result ; increment result CR EQU 0DH ; carriage return character White space can be used to improve readability repeat: inc result S. Dandamudi Chapter 9: Page 5 Data Allocation Variable declaration in a high-level language such as C char response int value float total double average_value specifies» Amount storage required (1 byte, 2 bytes, )» Label to identify the storage allocated (response, value, )» Interpretation of the bits stored (signed, floating point, ) Bit pattern is interpreted as 29,255 as a signed number 36,281 as an unsigned number S. Dandamudi Chapter 9: Page 6 3

4 Data Allocation (cont d) In assembly language, we use the define directive Define directive can be used» To reserve storage space» To label the storage space» To initialize»but no interpretation is attached to the bits stored Interpretation is up to the program code Define directive goes into the.data part of the assembly language program Define directive format [var-name] D? init-value [,init-value],... S. Dandamudi Chapter 9: Page 7 Five define directives Data Allocation (cont d) DB Define Byte ;allocates 1 byte DW Define Word ;allocates 2 bytes DD Define Doubleword ;allocates 4 bytes DQ Define Quadword ;allocates 8 bytes DT Define Ten bytes ;allocates 10 bytes Examples sorted DB y response DB? ;no initialization value DW float1 DD float2 DQ S. Dandamudi Chapter 9: Page 8 4

5 Data Allocation (cont d) Multiple definitions can be abbreviated Example message DB DB DB DB DB can be written as message DB More compactly as message DB B y e 0DH 0AH B, y, e,0dh,0ah Bye,0DH,0AH S. Dandamudi Chapter 9: Page 9 Data Allocation (cont d) Multiple definitions can be cumbersome to initialize data structures such as arrays Example To declare and initialize an integer array of 8 elements marks DW 0,0,0,0,0,0,0,0 What if we want to declare and initialize to zero an array of 200 elements? There is a better way of doing this than repeating zero 200 times in the above statement» Assembler provides a directive to do this (DUP directive) S. Dandamudi Chapter 9: Page 10 5

6 Data Allocation (cont d) Multiple initializations The DUP assembler directive allows multiple initializations to the same value Previous marks array can be compactly declared as marks DW 8 DUP (0) Examples table1 DW 10 DUP (?) ;10 words, uninitialized message DB 3 DUP ( Bye! ) ;12 bytes, initialized ; as Bye!Bye!Bye! Name1 DB 30 DUP (? ) ;30 bytes, each ; initialized to? S. Dandamudi Chapter 9: Page 11 Data Allocation (cont d) The DUP directive may also be nested Example stars DB 4 DUP(3 DUP ( * ),2 DUP (? ),5 DUP (! )) Reserves 40-bytes space and initializes it as ***??!!!!!***??!!!!!***??!!!!!***??!!!!! Example matrix DW 10 DUP (5 DUP (0)) defines a 10X5 matrix and initializes its elements to 0 This declaration can also be done by matrix DW 50 DUP (0) S. Dandamudi Chapter 9: Page 12 6

7 Data Allocation (cont d) Symbol Table Assembler builds a symbol table so we can refer to the allocated storage space by the associated label Example.DATA name offset value DW 0 value 0 sum DD 0 sum 2 marks DW 10 DUP (?) marks 6 message DB The grade is:,0 message 26 char1 DB? char1 40 S. Dandamudi Chapter 9: Page 13 Data Allocation (cont d) Correspondence to C Data Types Directive DB DW DD DQ DT C data type char int, unsigned float, long double internal intermediate float value S. Dandamudi Chapter 9: Page 14 7

8 Data Allocation (cont d) LABEL Directive LABEL directive provides another way to name a memory location Format: name LABEL type type can be BYTE WORD DWORD QWORD TWORD 1 byte 2 bytes 4 bytes 8 bytes 10 bytes S. Dandamudi Chapter 9: Page 15 Data Allocation (cont d) LABEL Directive Example.DATA count LABEL WORD Lo-count DB 0 Hi_count DB 0.CODE... mov Lo_count,AL mov Hi_count,CL count refers to the 16-bit value Lo_count refers to the low byte Hi_count refers to the high byte S. Dandamudi Chapter 9: Page 16 8

9 Where Are the Operands? Operands required by an operation can be specified in a variety of ways A few basic ways are: operand in a register register addressing mode operand in the instruction itself immediate addressing mode operand in memory variety of addressing modes direct and indirect addressing modes operand at an I/O port discussed in Chapter 19 S. Dandamudi Chapter 9: Page 17 Where Are the Operands? (cont d) Register addressing mode Operand is in an internal register Examples mov EAX,EBX ; 32-bit copy mov BX,CX ; 16-bit copy mov AL,CL ; 8-bit copy The mov instruction mov destination,source copies data from source to destination S. Dandamudi Chapter 9: Page 18 9

10 Where Are the Operands? (cont d) Register addressing mode (cont d) Most efficient way of specifying an operand» No memory access is required Instructions using this mode tend to be shorter» Fewer bits are needed to specify the register Compilers use this mode to optimize code total := 0 for (i = 1 to 400) total = total + marks[i] end for Mapping total and i to registers during the for loop optimizes the code S. Dandamudi Chapter 9: Page 19 Where Are the Operands? (cont d) Immediate addressing mode Data is part of the instruction» Ooperand is located in the code segment along with the instruction» Efficient as no separate operand fetch is needed» Typically used to specify a constant Example mov AL,75 This instruction uses register addressing mode for destination and immediate addressing mode for the source S. Dandamudi Chapter 9: Page 20 10

11 Where Are the Operands? (cont d) Direct addressing mode Data is in the data segment» Need a logical address to access data Two components: segment:offset» Various addressing modes to specify the offset component offset part is called effective address The offset is specified directly as part of instruction We write assembly language programs using memory labels (e.g., declared using DB, DW, LABEL,...)» Assembler computes the offset value for the label Uses symbol table to compute the offset of a label S. Dandamudi Chapter 9: Page 21 Where Are the Operands? (cont d) Direct addressing mode (cont d) Examples mov mov AL,response» Assembler replaces response by its effective address (i.e., its offset value from the symbol table) table1,56» table1 is declared as table1 DW 20 DUP (0)» Since the assembler replaces table1 by its effective address, this instruction refers to the first element of table1 In C, it is equivalent to table1[0] = 56 S. Dandamudi Chapter 9: Page 22 11

12 Where Are the Operands? (cont d) Direct addressing mode (cont d) Problem with direct addressing Useful only to specify simple variables Causes serious problems in addressing data types such as arrays» As an example, consider adding elements of an array Direct addressing does not facilitate using a loop structure to iterate through the array We have to write an instruction to add each element of the array Indirect addressing mode remedies this problem S. Dandamudi Chapter 9: Page 23 Where Are the Operands? (cont d) Indirect addressing mode The offset is specified indirectly via a register Sometimes called register indirect addressing mode For 16-bit addressing, the offset value can be in one of the three registers: BX, SI, or DI For 32-bit addressing, all 32-bit registers can be used Example mov AX,[BX] Square brackets [ ] are used to indicate that BX is holding an offset value» BX contains a pointer to the operand, not the operand itself S. Dandamudi Chapter 9: Page 24 12

13 Where Are the Operands? (cont d) Using indirect addressing mode, we can process arrays using loops Example: Summing array elements Load the starting address (i.e., offset) of the array into BX Loop for each element in the array» Get the value using the offset in BX Use indirect addressing» Add the value to the running total» Update the offset in BX to point to the next element of the array S. Dandamudi Chapter 9: Page 25 Where Are the Operands? (cont d) Loading offset value into a register Suppose we want to load BX with the offset value of table1 We cannot write mov BX,table1 Two ways of loading offset value» Using OFFSET assembler directive Executed only at the assembly time»using lea instruction This is a processor instruction Executed at run time S. Dandamudi Chapter 9: Page 26 13

14 Where Are the Operands? (cont d) Loading offset value into a register (cont d) Using OFFSET assembler directive The previous example can be written as mov BX,OFFSET table1 Using lea (load effective address) instruction The format of lea instruction is lea register,source The previous example can be written as lea BX,table1 S. Dandamudi Chapter 9: Page 27 Where Are the Operands? (cont d) Loading offset value into a register (cont d) Which one to use -- OFFSET or lea? Use OFFSET if possible» OFFSET incurs only one-time overhead (at assembly time)» lea incurs run time overhead (every time you run the program) May have to use lea in some instances» When the needed data is available at run time only An index passed as a parameter to a procedure» We can write lea BX,table1[SI] to load BX with the address of an element of table1 whose index is in SI register» We cannot use the OFFSET directive in this case S. Dandamudi Chapter 9: Page 28 14

15 Default Segments In register indirect addressing mode 16-bit addresses» Effective addresses in BX, SI, or DI is taken as the offset into the data segment (relative to DS)» For BP and SP registers, the offset is taken to refer to the stack segment (relative to SS) 32-bit addresses» Effective address in EAX, EBX, ECX, EDX, ESI, and EDI is relative to DS» Effective address in EBP and ESP is relative to SS push and pop are always relative to SS S. Dandamudi Chapter 9: Page 29 Default Segments (cont d) Default segment override Possible to override the defaults by using override prefixes» CS, DS, SS, ES, FS, GS Example 1» We can use add AX,SS:[BX] to refer to a data item on the stack Example 2» We can use add AX,DS:[BP] to refer to a data item in the data segment S. Dandamudi Chapter 9: Page 30 15

16 Data Transfer Instructions We will look at three instructions mov (move)» Actually copy xchg (exchange)» Exchanges two operands xlat (translate)» Translates byte values using a translation table Other data transfer instructions such as movsx (move sign extended) movzx (move zero extended) are discussed in Chapter 12 S. Dandamudi Chapter 9: Page 31 Data Transfer Instructions (cont d) The mov instruction The format is mov destination,source» Copies the value from source to destination» source is not altered as a result of copying» Both operands should be of same size» source and destination cannot both be in memory Most Pentium instructions do not allow both operands to be located in memory Pentium provides special instructions to facilitate memory-to-memory block copying of data S. Dandamudi Chapter 9: Page 32 16

17 Data Transfer Instructions (cont d) The mov instruction Five types of operand combinations are allowed: Instruction type Example mov register,register mov DX,CX mov register,immediate mov BL,100 mov register,memory mov BX,count mov memory,register mov count,si mov memory,immediate mov count,23 The operand combinations are valid for all instructions that require two operands S. Dandamudi Chapter 9: Page 33 Data Transfer Instructions (cont d) Ambiguous moves: PTR directive For the following data definitions.data table1 DW 20 DUP (0) status DB 7 DUP (1) the last two mov instructions are ambiguous mov BX,OFFSET table1 mov SI,OFFSET status mov [BX],100 mov [SI],100 Not clear whether the assembler should use byte or word equivalent of 100 S. Dandamudi Chapter 9: Page 34 17

18 Data Transfer Instructions (cont d) Ambiguous moves: PTR directive The PTR assembler directive can be used to clarify The last two mov instructions can be written as mov mov WORD PTR [BX],100 BYTE PTR [SI],100 WORD and BYTE are called type specifiers We can also use the following type specifiers: DWORD for doubleword values QWORD for quadword values TWORD for ten byte values S. Dandamudi Chapter 9: Page 35 Data Transfer Instructions (cont d) The xchg instruction The syntax is xchg operand1,operand2 Exchanges the values of operand1 and operand2 Examples xchg xchg xchg EAX,EDX response,cl total,dx Without the xchg instruction, we need a temporary register to exchange values using only the mov instruction S. Dandamudi Chapter 9: Page 36 18

19 Data Transfer Instructions (cont d) The xchg instruction The xchg instruction is useful for conversion of 16-bit data between little endian and big endian forms Example: mov AL,AH converts the data in AX into the other endian form Pentium provides bswap instruction to do similar conversion on 32-bit data bswap 32-bit register bswap works only on data located in a 32-bit register S. Dandamudi Chapter 9: Page 37 Data Transfer Instructions (cont d) The xlat instruction The xlat instruction translates bytes The format is xlatb To use xlat instruction» BX should be loaded with the starting address of the translation table» AL must contain an index in to the table Index value starts at zero» The instruction reads the byte at this index in the translation table and stores this value in AL The index value in AL is lost» Translation table can have at most 256 entries (due to AL) S. Dandamudi Chapter 9: Page 38 19

20 Data Transfer Instructions (cont d) The xlat instruction Example: Encrypting digits Input digits: Encrypted digits: DATA xlat_table DB CODE mov BX,OFFSET xlat_table GetCh AL sub AL, 0 ; converts input character to index xlatb ; AL = encrypted digit character PutCh AL... S. Dandamudi Chapter 9: Page 39 Pentium Assembly Instructions Pentium provides several types of instructions Brief overview of some basic instructions: Arithmetic instructions Jump instructions Loop instruction Logical instructions Shift instructions Rotate instructions These instructions allow you to write reasonable assembly language programs S. Dandamudi Chapter 9: Page 40 20

21 INC and DEC instructions Arithmetic Instructions Format: inc destination dec destination Semantics: destination = destination +/- 1» destination can be 8-, 16-, or 32-bit operand, in memory or register No immediate operand Examples inc dec BX value S. Dandamudi Chapter 9: Page 41 Arithmetic Instructions (cont d) Add instructions Format: add destination,source Semantics: destination = destination + source Examples add add EBX,EAX value,35 inc EAX is better than add EAX,1 inc takes less space Both execute at about the same speed S. Dandamudi Chapter 9: Page 42 21

22 Arithmetic Instructions (cont d) Add instructions Addition with carry Format: adc destination,source Semantics: destination = destination + source + CF Example: 64-bit addition add EAX,ECX ; add lower 32 bits adc EBX,EDX ; add upper 32 bits with carry 64-bit result in EBX:EAX S. Dandamudi Chapter 9: Page 43 Arithmetic Instructions (cont d) Subtract instructions Format: sub destination,source Semantics: destination = destination - source Examples sub sub EBX,EAX value,35 dec EAX is better than sub EAX,1 dec takes less space Both execute at about the same speed S. Dandamudi Chapter 9: Page 44 22

23 Arithmetic Instructions (cont d) Subtract instructions Subtract with borrow Format: sbb destination,source Semantics: destination = destination - source - CF Like the adc, sbb is useful in dealing with more than 32-bit numbers Negation neg destination Semantics: destination = 0 - destination S. Dandamudi Chapter 9: Page 45 Arithmetic Instructions (cont d) CMP instruction Format: cmp destination,source Semantics: destination - source destination and source are not altered Useful to test relationship (>, =) between two operands Used in conjunction with conditional jump instructions for decision making purposes Examples cmp EBX,EAX cmp count,100 S. Dandamudi Chapter 9: Page 46 23

24 Format: jmp label Unconditional Jump Semantics:» Execution is transferred to the instruction identified by label Target can be specified in one of two ways Directly» In the instruction itself Indirectly» Through a register or memory» Discussed in Chapter 12 S. Dandamudi Chapter 9: Page 47 Unconditional Jump (cont d) Example Two jump instructions Forward jump jmp CX_init_done Backward jump jmp repeat1 Programmer specifies target by a label Assembler computes the offset using the symbol table... mov CX,10 jmp CX_init_done init_cx_20: mov CX,20 CX_init_done: mov AX,CX repeat1: dec CX... jmp repeat1... S. Dandamudi Chapter 9: Page 48 24

25 Unconditional Jump (cont d) Address specified in the jump instruction is not the absolute address Uses relative address» Specifies relative byte displacement between the target instruction and the instruction following the jump instruction» Displacement is w.r.t the instruction following jmp Reason: IP points to this instruction after reading jump Execution of jmp involves adding the displacement value to current IP Displacement is a signed 16-bit number» Negative value for backward jumps» Positive value for forward jumps S. Dandamudi Chapter 9: Page 49 Target Location Inter-segment jump Target is in another segment CS = target-segment (2 bytes) IP = target-offset (2 bytes)» Called far jumps (needs five bytes to encode jmp) Intra-segment jumps Target is in the same segment IP = IP + relative-displacement (1 or 2 bytes) Uses 1-byte displacement if target is within 128 to +127» Called short jumps (needs two bytes to encode jmp) If target is outside this range, uses 2-byte displacement» Called near jumps (needs three bytes to encode jmp) S. Dandamudi Chapter 9: Page 50 25

26 Target Location (cont d) In most cases, the assembler can figure out the type of jump For backward jumps, assembler can decide whether to use the short jump form or not For forward jumps, it needs a hint from the programmer Use SHORT prefix to the target label If such a hint is not given» Assembler reserves three bytes for jmp instruction» If short jump can be used, leaves one byte of nop (no operation) See the next example for details S. Dandamudi Chapter 9: Page 51 Example EB 0C jmp SHORT CX_init_done = 0C B9 000A mov CX, A EB jmp CX_init_done nop D = init_cx_20: D B mov CX, E9 00D0 jmp near_jump 00E = D0 14 CX_init_done: B C1 mov AX,CX S. Dandamudi Chapter 9: Page 52 26

27 Example (cont d) 16 repeat1: dec CX EB FD jmp repeat = -3 = FDH DB EB 03 jmp SHORT short_jump 00E0-00DD = DD B9 FF00 mov CX, 0FF00H 86 short_jump: 87 00E0 BA 0020 mov DX, 20H 88 near_jump: 89 00E3 E9 FF27 jmp init_cx_20 000D - 00E6 = -217 = FF27H S. Dandamudi Chapter 9: Page 53 Conditional Jumps (cont d) Format: j<cond> lab Execution is transferred to the instruction identified by label only if <cond> is met Example: Testing for carriage return read_char:... cmp AL,0DH ; 0DH = ASCII carriage return je CR_received inc CL jmp read_char... CR_received: S. Dandamudi Chapter 9: Page 54 27

28 Conditional Jumps (cont d) Some conditional jump instructions Treats operands of the CMP instruction as signed numbers je jg jl jge jle jne jump if equal jump if greater jump if less jump if greater or equal jump if less or equal jump if not equal S. Dandamudi Chapter 9: Page 55 Conditional Jumps (cont d) Conditional jump instructions can also test values of the individual flags jz jump if zero (i.e., if ZF = 1) jnz jump if not zero (i.e., if ZF = 0) jc jump if carry (i.e., if CF = 1) jnc jump if not carry (i.e., if CF = 0) jz is synonymous for je jnz is synonymous for jne S. Dandamudi Chapter 9: Page 56 28

29 target:... cmp AX,BX je target mov CX,10... A Note on Conditional Jumps All conditional jumps are encoded using 2 bytes Treated as short jumps What if the target is outside this range? traget is out of range for a short jump Use this code to get around target:... cmp AX,BX jne skip1 jmp target skip1: mov CX,10... S. Dandamudi Chapter 9: Page 57 Loop Instructions Unconditional loop instruction Format: loop target Semantics:» Decrements CX and jumps to target if CX 0 CX should be loaded with a loop count value Example: Executes loop body 50 times mov CX,50 repeat: <loop body> loop repeat... S. Dandamudi Chapter 9: Page 58 29

30 Loop Instructions (cont d) The previous example is equivalent to mov CX,50 repeat: <loop body> dec CX Surprisingly, dec jnz repeat... jnz CX repeat executes faster than loop repeat S. Dandamudi Chapter 9: Page 59 Loop Instructions (cont d) Conditional loop instructions loope/loopz» Loop while equal/zero CX = CX 1 ff (CX = 0 and ZF = 1) jump to target loopne/loopnz» Loop while not equal/not zero CX = CX 1 ff (CX = 0 and ZF = 0) jump to target S. Dandamudi Chapter 9: Page 60 30

31 Logical Instructions Format: and destination,source or destination,source xor destination,source not destination Semantics:» Performs the standard bitwise logical operations result goes to destination test is a non-destructive and instruction test destination,source Performs logical AND but the result is not stored in destination (like the CMP instruction) S. Dandamudi Chapter 9: Page 61 Example:... Logical Instructions (cont d) and jz AL,01H ; test the least significant bit bit_is_zero <bit 1 code> jmp skip1 bit_is_zero: <bit 0 code> skip1:... test instruction is better in place of and S. Dandamudi Chapter 9: Page 62 31

32 Shift Instructions Two types of shifts» Logical» Arithmetic Logical shift instructions Shift left shl destination,count shl destination,cl Shift right shr destination,count shr destination,cl Semantics:» Performs left/right shift of destination by the value in count or CL register CL register contents are not altered S. Dandamudi Chapter 9: Page 63 Logical shift Shift Instructions (cont d) Bit shifted out goes into the carry flag» Zero bit is shifted in at the other end S. Dandamudi Chapter 9: Page 64 32

33 Shift Instructions (cont d) count is an immediate value shl AX,5 Specification of count greater than 31 is not allowed» If a greater value is specified, only the least significant 5 bits are used CL version is useful if shift count is known at run time» Ex: when the shift count value is passed as a parameter in a procedure call» Only the CL register can be used Shift count value should be loaded into CL mov CL,5 shl AX,CL S. Dandamudi Chapter 9: Page 65 Arithmetic shift Shift Instructions (cont d) Two versions as in logical shift sal/sar destination,count sal/sar destination,cl S. Dandamudi Chapter 9: Page 66 33

34 Double Shift Instructions Double shift instructions work on either 32- or 64- bit operands Format Takes three operands shld dest,src,count ; left shift shrd dest,src,count ; right shift dest can be in memory or register src must be a register count can be an immediate value or in CL as in other shift instructions S. Dandamudi Chapter 9: Page 67 Double Shift Instructions (cont d) src is not modified by doubleshift instruction Only dest is modified Shifted out bit goes into the carry flag S. Dandamudi Chapter 9: Page 68 34

35 Rotate Instructions Two types of ROTATE instructions Rotate without carry» rol (ROtate Left)» ror (ROtate Right) Rotate with carry» rcl (Rotate through Carry Left)» rcr (Rotate through Carry Right) Format of ROTATE instructions is similar to the SHIFT instructions» Supports two versions Immediate count value Count value in CL register S. Dandamudi Chapter 9: Page 69 Rotate Instructions (cont d) Bit shifted out goes into the carry flag as in SHIFT instructions S. Dandamudi Chapter 9: Page 70 35

36 Rotate Instructions (cont d) Bit shifted out goes into the carry flag as in SHIFT instructions S. Dandamudi Chapter 9: Page 71 Rotate Instructions (cont d) Example: Shifting 64-bit numbers Multiplies a 64-bit value in EDX:EAX by 16» Rotate version mov CX,4 shift_left: shl EAX,1 rcl EDX,1 loop shift_left» Doubleshift version shld EDX,EAX,4 shl EAX,4 Division can be done in a similar a way S. Dandamudi Chapter 9: Page 72 36

37 Defining Constants Assembler provides two directives:» EQU directive No reassignment String constants can be defined» = directive Can be reassigned No string constants Defining constants has two advantages: Improves program readability Helps in software maintenance» Multiple occurrences can be changed from a single place Convention» We use all upper-case letters for names of constants S. Dandamudi Chapter 9: Page 73 Defining Constants (cont d) The EQU directive Syntax: name EQU expression Assigns the result of expression to name The expression is evaluated at assembly time Similar to #define in C Examples NUM_OF_ROWS EQU 50 NUM_OF_COLS EQU 10 ARRAY_SIZE EQU NUM_OF_ROWS * NUM_OF_COLS Can also be used to define string constants JUMP EQU jmp S. Dandamudi Chapter 9: Page 74 37

38 Defining Constants (cont d) The = directive Syntax: name = expression Similar to EQU directive Two key differences:» Redefinition is allowed count = 0... count = 99 is valid» Cannot be used to define string constants or to redefine keywords or instruction mnemonics Example: JUMP = jmp is not allowed S. Dandamudi Chapter 9: Page 75 Macros Macros can be defined with MACRO and ENDM Format macro_name MACRO[parameter1, parameter2,...] macro body ENDM A macro can be invoked using macro_name [argument1, argument2, ] Example: Definition Invocation multax_by_16 MACRO... sal AX,4 mov AX,27 ENDM multax_by_16... S. Dandamudi Chapter 9: Page 76 38

39 Macros (cont d) Macros can be defined with parameters» More flexible» More useful Example mult_by_16 MACRO operand sal operand,4 ENDM To multiply a byte in DL register mult_by_16 DL To multiply a memory variable count mult_by_16 count S. Dandamudi Chapter 9: Page 77 Macros (cont d) Example: To exchange two memory words Memory-to-memory transfer Wmxchg MACRO operand1, operand2 xchg AX,operand1 xchg AX,operand2 xchg AX,operand1 ENDM S. Dandamudi Chapter 9: Page 78 39

40 Illustrative Examples Five examples in this chapter Conversion of ASCII to binary representation (BINCHAR.ASM) Conversion of ASCII to hexadecimal by character manipulation (HEX1CHAR.ASM) Conversion of ASCII to hexadecimal using the XLAT instruction (HEX2CHAR.ASM) Conversion of lowercase letters to uppercase by character manipulation (TOUPPER.ASM) Sum of individual digits of a number (ADDIGITS.ASM) Last slide S. Dandamudi Chapter 9: Page 79 40

Language of x86 processor family

Language of x86 processor family 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,

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

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

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

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

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

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

Chapter 3: Addressing Modes

Chapter 3: Addressing Modes Chapter 3: Addressing Modes Chapter 3 Addressing Modes Note: Adapted from (Author Slides) Instructor: Prof. Dr. Khalid A. Darabkh 2 Introduction Efficient software development for the microprocessor requires

More information

ORG ; TWO. Assembly Language Programming

ORG ; TWO. Assembly Language Programming Dec 2 Hex 2 Bin 00000010 ORG ; TWO Assembly Language Programming OBJECTIVES this chapter enables the student to: Explain the difference between Assembly language instructions and pseudo-instructions. Identify

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

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

Intel 8086: Instruction Set

Intel 8086: Instruction Set IUST-EE (Chapter 6) Intel 8086: Instruction Set 1 Outline Instruction Set Data Transfer Instructions Arithmetic Instructions Bit Manipulation Instructions String Instructions Unconditional Transfer Instruction

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

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

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

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

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

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

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

Q1: Multiple choice / 20 Q2: Memory addressing / 40 Q3: Assembly language / 40 TOTAL SCORE / 100

Q1: Multiple choice / 20 Q2: Memory addressing / 40 Q3: Assembly language / 40 TOTAL SCORE / 100 16.317: Microprocessor-Based Systems I Summer 2012 Exam 1 July 20, 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

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

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

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

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

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to: Introduction Efficient software development for the microprocessor requires a complete familiarity with the addressing modes employed by each instruction. This chapter explains the operation of the stack

More information

CS/ECE/EEE/INSTR F241 MICROPROCESSOR PROGRAMMING & INTERFACING MODULE 4: 80X86 INSTRUCTION SET QUESTIONS ANUPAMA KR BITS, PILANI KK BIRLA GOA CAMPUS

CS/ECE/EEE/INSTR F241 MICROPROCESSOR PROGRAMMING & INTERFACING MODULE 4: 80X86 INSTRUCTION SET QUESTIONS ANUPAMA KR BITS, PILANI KK BIRLA GOA CAMPUS CS/ECE/EEE/INSTR F241 MICROPROCESSOR PROGRAMMING & INTERFACING MODULE 4: 80X86 INSTRUCTION SET QUESTIONS ANUPAMA KR BITS, PILANI KK BIRLA GOA CAMPUS Q1. IWrite an ALP that will examine a set of 20 memory

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

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

Chapter 11. Addressing Modes

Chapter 11. Addressing Modes Chapter 11 Addressing Modes 1 2 Chapter 11 11 1 Register addressing mode is the most efficient addressing mode because the operands are in the processor itself (there is no need to access memory). Chapter

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

A4 Sample Solution Ch3

A4 Sample Solution Ch3 A4 Sample Solution Ch3 2. AL, AH, BL, BH,CL,CH,DLl, DH 3. AX, BX, CX, DX, SP, BP, SI, DI, CS, DS, ES, SS, FS, GS 4. EAX, EBX, ECX, EDX, ESP, EBP, EDI, ESI 5. RAX, RBX, RCX, RDX, RSP, RBP, RSI, RDI and

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

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

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

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

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

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

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

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86 Lecture 15 Intel Manual, Vol. 1, Chapter 3 Hampden-Sydney College Fri, Mar 6, 2009 Outline 1 2 Overview See the reference IA-32 Intel Software Developer s Manual Volume 1: Basic, Chapter 3. Instructions

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

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998 Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998 Assembler Syntax Everything looks like this: label: instruction dest,src instruction label Comments: comment $ This is a comment

More information

Mr. Sapan Naik 1. Babu Madhav Institute of Information Technology, UTU

Mr. Sapan Naik 1. Babu Madhav Institute of Information Technology, UTU 5 Years Integrated M.Sc.(IT) Semester 4 060010402 System Programming Question Bank Unit 1: Introduction 1. Write the decimal equivalent for each integral power of 2 from 2! to 2!". 2. Convert the following

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

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY BACKGROUND Segment The "SEGMENT" and "ENDS" directives indicate to the assembler the beginning and ending of a segment and have the following format label SEGMENT [options] ;place the statements belonging

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

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

Addressing Modes on the x86

Addressing Modes on the x86 Addressing Modes on the x86 register addressing mode mov ax, ax, mov ax, bx mov ax, cx mov ax, dx constant addressing mode mov ax, 25 mov bx, 195 mov cx, 2056 mov dx, 1000 accessing data in memory There

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

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM EXPERIMENT WRITE UP AIM: Assembly language program to search a number in given array. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

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

Addressing Modes. Outline

Addressing Modes. Outline Addressing Modes Chapter 11 S. Dandamudi Outline Addressing modes Simple addressing modes Register addressing mode Immediate addressing mode Memory addressing modes 16-bit and 32-bit addressing» Operand

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

We will first study the basic instructions for doing multiplications and divisions

We will first study the basic instructions for doing multiplications and divisions MULTIPLICATION, DIVISION AND NUMERICAL CONVERSIONS We will first study the basic instructions for doing multiplications and divisions We then use these instructions to 1. Convert a string of ASCII digits

More information

EEM336 Microprocessors I. Addressing Modes

EEM336 Microprocessors I. Addressing Modes EEM336 Microprocessors I Addressing Modes Introduction Efficient software development for the microprocessor requires a complete familiarity with the addressing modes employed by each instruction. This

More information

Assembly Language Each statement in an assembly language program consists of four parts or fields.

Assembly Language Each statement in an assembly language program consists of four parts or fields. Chapter 3: Addressing Modes Assembly Language Each statement in an assembly language program consists of four parts or fields. The leftmost field is called the label. - used to identify the name of a memory

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

Integer Arithmetic. Computer Organization and Assembly Languages Yung-Yu Chuang 2005/11/17. with slides by Kip Irvine

Integer Arithmetic. Computer Organization and Assembly Languages Yung-Yu Chuang 2005/11/17. with slides by Kip Irvine Integer Arithmetic Computer Organization and Assembly Languages Yung-Yu Chuang 2005/11/17 with slides by Kip Irvine Announcements Assignment #2 is due next week. Assignment #3 box filter is online now,

More information

Summer 2003 Lecture 4 06/14/03

Summer 2003 Lecture 4 06/14/03 Summer 2003 Lecture 4 06/14/03 LDS/LES/LSS General forms: lds reg,mem lseg reg,mem Load far pointer ~~ outside of current segment {E.g., load reg w/value @ mem, & seg w/mem+2 XCHG Exchange values General

More information

CSE351 Spring 2018, Midterm Exam April 27, 2018

CSE351 Spring 2018, Midterm Exam April 27, 2018 CSE351 Spring 2018, Midterm Exam April 27, 2018 Please do not turn the page until 11:30. Last Name: First Name: Student ID Number: Name of person to your left: Name of person to your right: Signature indicating:

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

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

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

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

The x86 Architecture

The x86 Architecture The x86 Architecture Lecture 24 Intel Manual, Vol. 1, Chapter 3 Robb T. Koether Hampden-Sydney College Fri, Mar 20, 2015 Robb T. Koether (Hampden-Sydney College) The x86 Architecture Fri, Mar 20, 2015

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

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

Inline Assembler. Willi-Hans Steeb and Yorick Hardy. International School for Scientific Computing

Inline Assembler. Willi-Hans Steeb and Yorick Hardy. International School for Scientific Computing Inline Assembler Willi-Hans Steeb and Yorick Hardy International School for Scientific Computing e-mail: steebwilli@gmail.com Abstract We provide a collection of inline assembler programs. 1 Using the

More information

EEM336 Microprocessors I. Data Movement Instructions

EEM336 Microprocessors I. Data Movement Instructions EEM336 Microprocessors I Data Movement Instructions Introduction This chapter concentrates on common data movement instructions. 2 Chapter Objectives Upon completion of this chapter, you will be able to:

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

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY BACKGROUND 8086 CPU has 8 general purpose registers listed below: AX - the accumulator register (divided into AH / AL): 1. Generates shortest machine code 2. Arithmetic, logic and data transfer 3. One

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

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

Week /8086 Microprocessor Programming II

Week /8086 Microprocessor Programming II Week 5 8088/8086 Microprocessor Programming II Quick Review Shift & Rotate C Target register or memory SHL/SAL 0 C SHR 0 SAR C Sign Bit 2 Examples Examples Ex. Ex. Ex. SHL dest, 1; SHL dest,cl; SHL dest,

More information

16.317: Microprocessor Systems Design I Spring 2014

16.317: Microprocessor Systems Design I Spring 2014 16.317: Microprocessor Systems Design I Spring 2014 Exam 1 Solution 1. (20 points, 5 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by

More information

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil Microprocessor By Mrs. R.P.Chaudhari Mrs.P.S.Patil Chapter 1 Basics of Microprocessor CO-Draw Architecture Of 8085 Salient Features of 8085 It is a 8 bit microprocessor. It is manufactured with N-MOS technology.

More information

CS401 Assembly Language Solved MCQS From Midterm Papers

CS401 Assembly Language Solved MCQS From Midterm Papers CS401 Assembly Language Solved MCQS From Midterm Papers May 14,2011 MC100401285 Moaaz.pk@gmail.com MC100401285@gmail.com PSMD01(IEMS) Question No:1 ( Marks: 1 ) - Please choose one The first instruction

More information

Integer Arithmetic. Pu-Jen Cheng. Adapted from the slides prepared by Kip Irvine for the book, Assembly Language for Intel-Based Computers, 5th Ed.

Integer Arithmetic. Pu-Jen Cheng. Adapted from the slides prepared by Kip Irvine for the book, Assembly Language for Intel-Based Computers, 5th Ed. Computer Organization & Assembly Languages Integer Arithmetic Pu-Jen Cheng Adapted from the slides prepared by Kip Irvine for the book, Assembly Language for Intel-Based Computers, 5th Ed. Chapter Overview

More information

CS241 Computer Organization Spring 2015 IA

CS241 Computer Organization Spring 2015 IA CS241 Computer Organization Spring 2015 IA-32 2-10 2015 Outline! Review HW#3 and Quiz#1! More on Assembly (IA32) move instruction (mov) memory address computation arithmetic & logic instructions (add,

More information

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections x86 Assembler Computer Systems: Sections 3.1-3.5 Disclaimer I am not an x86 assembler expert. I have never written an x86 assembler program. (I am proficient in IBM S/360 Assembler and LC3 Assembler.)

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

Chapter 7 Integer Arithmetic

Chapter 7 Integer Arithmetic Chapter 7 Integer Arithmetic 7.1 Introduction 193 7.2 Shift and Rotate Instructions 194 7.2.1 Logical Shifts and Arithmetic Shifts 194 7.2.2 SHL Instruction 195 7.2.3 SHR Instruction 196 7.2.4 SAL and

More information

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM EXPERIMENT WRITE UP AIM: Assembly language program for 16 bit BCD addition LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM TOOLS/SOFTWARE

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

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

CS401 Assembly Language Solved Subjective MAY 03,2012 From Midterm Papers. MC

CS401 Assembly Language Solved Subjective MAY 03,2012 From Midterm Papers. MC CS401 Assembly Language Solved Subjective MAY 03,2012 From Midterm Papers MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 MIDTERM FALL 2011 CS401 Assembly Language Q: Affected flag of AND operation

More information

Computer Architecture 1 ح 303

Computer Architecture 1 ح 303 Lecture 4 A. Addressing MODES 1. Introduction to assembly language programming: Program is a sequence of commands used to tell a microcomputer what to do. Each command in a program is an instruction Programs

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

Introduction to IA-32. Jo, Heeseung

Introduction to IA-32. Jo, Heeseung Introduction to IA-32 Jo, Heeseung IA-32 Processors Evolutionary design Starting in 1978 with 8086 Added more features as time goes on Still support old features, although obsolete Totally dominate computer

More information

UNIT 4. Modular Programming

UNIT 4. Modular Programming 1 UNIT 4. Modular Programming Program is composed from several smaller modules. Modules could be developed by separate teams concurrently. The modules are only assembled producing.obj modules (Object modules).

More information

Basic Execution Environment

Basic Execution Environment Basic Execution Environment 3 CHAPTER 3 BASIC EXECUTION ENVIRONMENT This chapter describes the basic execution environment of an Intel Architecture processor as seen by assembly-language programmers.

More information

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,... COMPUTER ARCHITECTURE II: MICROPROCESSOR PROGRAMMING We can study computer architectures by starting with the basic building blocks Transistors and logic gates To build more complex circuits Adders, decoders,

More information

INTRODUCTION TO IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung INTRODUCTION TO IA-32 Jo, Heeseung IA-32 PROCESSORS Evolutionary design Starting in 1978 with 8086 Added more features as time goes on Still support old features, although obsolete Totally dominate computer

More information

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature CSE2421 FINAL EXAM SPRING 2013 Name KEY Instructions: This is a closed-book, closed-notes, closed-neighbor exam. Only a writing utensil is needed for this exam. No calculators allowed. If you need to go

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

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

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

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

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

Computer Architecture and System Software Lecture 04: Floating Points & Intro to Assembly

Computer Architecture and System Software Lecture 04: Floating Points & Intro to Assembly Computer Architecture and System Software Lecture 04: Floating Points & Intro to Assembly Instructor: Rob Bergen Applied Computer Science University of Winnipeg Decimal Addition Review decimal addition

More information