Presentation is loading. Please wait.

Presentation is loading. Please wait.

CDP ECE 291 -- Spring 2000 ECE 291 Spring 2000 Lecture 4: The 80x86 Instruction Set Architecture Registers-Instructions Constantine D. Polychronopoulos.

Similar presentations


Presentation on theme: "CDP ECE 291 -- Spring 2000 ECE 291 Spring 2000 Lecture 4: The 80x86 Instruction Set Architecture Registers-Instructions Constantine D. Polychronopoulos."— Presentation transcript:

1 CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 4: The 80x86 Instruction Set Architecture Registers-Instructions Constantine D. Polychronopoulos

2 CDP ECE Spring 2000 Instruction Format ALL instructions have the following specifiers: –OPCODE: a field that specifies the operation to be done –OPERAND(S): one or more fields giving the operands or the location where the operands can be found –DESTINATION: a field that specifies the location (register or memory) where the result of the operation is to be stored –[Descriptor fields]: Special bit specifiers that allow for different interpretation of the same field (e.g. register or offset specifier) ASSEMBLY INSTRUCTIONS: symbolic (mnemonic) versions of machine instructions MACHINE INSTR. Or BINARY CODE: Binary codes that give the specific value for each of the above fields Assembly program ==> ASSEMBLER (MASM) ==> Machine code

3 CDP ECE Spring 2000 Instruction Format: x86 In 80x86 instructions can vary in length from 8-bits (1b) to more than 100-bits (13b) REAL MODE: –Default instruction size is 16-bits 16-bit registers & 16-bit offset fields RPOTECTED MODE: –Default instruction size is 32-bits (x386 and above) 32-bit registers & 32-bit offset fields –D-bit in descriptor specifies real or protected mode: D=0: (real-mode) 16-bit instructions, register values and addresses D=1: (protected mode) 32-bit instructions, reg. values and addresses

4 CDP ECE Spring 2000 Addressing Modes Immediate: Move an immediate value (in the field itself) to the destination register or memory location: –MOVAX, 7F55H Register: Move a byte or word from the source register to the destination register or memory location: –MOVAX, BX Direct: Move a byte/word from a memory location to a register or memory location: –MOVAX, [7777H]

5 CDP ECE Spring 2000 Addressing Modes Base-relative or indexed: Move a byte/word between a register and mem. Location specified by an index (DI or SI) or base register (BP or BX): –MOVAX, [BX] Register-relative: Move a byte/word between a register and mem. Location specified by an index OR base register + offset: –MOVAX, [DI H] Base-relative and indexed: Move a byte/word between a register and mem. Location specified by a base register PLUS an index register PLUS offset: –MOVAX, [SP + DI H]

6 CDP ECE Spring 2000 Addressing Modes: Register Instruction CommentAddr. Mode Memory Cont. OP Dest Source MOV AX, BX Move to AX the 16-bit value in BX Register 89 D8 MOV AX, DI Move to AX the 16-bit value in DI Register89F8 MOV AH, AL Move to AH the 8-bit value in AL Register88C4

7 CDP ECE Spring 2000 Addressing Modes - Immediate Instruction Comment Addr. Mode Memory Cont. OP Dest Source MOV AH, 12H Move to AH the byte value 12HImmediateB412 MOV AX, 1234H Move to AX the value 1234H ImmediateB MOV AX, CONST Move to AX the constant CONSTImmediate B8LSB MSB MOV AX, OFFSET x Move to AX the address (offset) of Immediate B 8 LSB MSB variable x MASM Notation

8 CDP ECE Spring 2000 Addressing Modes: Direct & Indexed Instruction Comment Addr. Mode Memory Cont. OP Dest Source MOV AX, [1234H] Move to AX the value at memoryDirect A location 1234H (uses default segment, DS) MOV AX, x Move to AX the value of M[x] Direct A1 LSB MSB (uses default segment, DS) MASM Notation MOV x, AX Move to M[x] the value of AXDirect A3 LSB MSB (uses default segment, DS) MASM Notation MOV AX, [DI] Move to AX the value at M[DI]Indexed8B 05 (uses default segment, DS) MOV [DI], AX Move to M[DI] the value AXIndexed89 05 (uses default segment, DS)

9 CDP ECE Spring 2000 Instruction Comment Addr. Mode Memory Cont. OP Dest Source MOV AX, [BX] Move to AX the value M[BX] Base-relative8B 07 (uses default segment, DS) MOV [BX], AX Move to M[BX] the value AX Base-relative (uses default segment, DS) MOV AX, [BP] Move to AX the value of M[BP] Base-relative 8B 46 (uses stack segment, SS) MOV [BP], AX Move to M[BP] the value of AX Base-relative (uses stack segment, SS) Addressing Modes: Base-relat.

10 CDP ECE Spring 2000 Instruction CommentAddr. ModeMemory Contents OP Dest Source MOV AX, offs[BX] Move to AX the value M[offs+BX] Base-relative 8B 87 LSB MSB (uses default segment, DS) Direct MOV offs[BX], AX Move to M[offs+BX] the value AX Base-relative LSB MSB (uses default segment, DS) Direct MOV AX, [BX+DI] Move to AX the value M[BX+DI] Base-relative 8B 01 (uses default segment, DS) Direct MOV [BX+DI], AX Move to M[BX+DI] the value Base-relative AX (uses default segment, DS) Indexed MOV AX, [BX+DI+1234H] Move to AX the value pointed to by Base-relative 8B M[BX+DI+1234H] Indexed Direct (uses default segment, DS) Addressing Modes: Base-relat./Direct/Indexed-Direct

11 CDP ECE Spring 2000 Memory Model: Real & Protected Modes Due to downward compatibility with previous generations all x86 processors support real address mode which allows direct addressing of only 1Mb of memory (20 bits) - recall that: –Memory address = segment register + offset where segment reg. Is 16-bits left-shifted by 4 bits - hence a 20- bit address. Protected mode allows extended memory of 4Gb or even 64Gb: An SDT (segment description table) is used to get the starting address of memory segment to be addressed. The original DS or CS register is used as an index into SDT whose entry points to actual memory segment. Offset is added to latter to form address: –Memory addr. = SDT[segment register] + offset

12 CDP ECE Spring 2000 Memory Model (Cont.) ALL memory is allocated and managed in units of 64Kb segments Segments are used to organize different partitions of memory for different objects (with different access restrictions): –user code & user data –user stack area –system code and data –memory-mapped I/O devices and other peripherals The segment starting address must first be loaded to DS or CS before any access to that segment via x86 mem. Instructions. Before x386 only real memory addressing was available. But protected mode was introduced starting with the 32-bit architectures. Default is always real mode for all x86 processors.

13 CDP ECE Spring 2000 Instruction Format ALL instructions have the following specifiers: –OPCODE: a field that specifies the operation to be done –OPERAND(S): one or more fields giving the operands or the location where the operands can be found –DESTINATION: a field that specifies the location (register or memory) where the result of the operation is to be stored –[Descriptor fields]: Special bit specifiers that allow for different interpretation of the same field (e.g. register or offset specifier) ASSEMBLY INSTRUCTIONS: symbolic (mnemonic) versions of machine instructions MACHINE INSTR. Or BINARY CODE: Binary codes that give the specific value for each of the above fields Assembly program ==> ASSEMBLER (MASM) ==> Machine code

14 CDP ECE Spring 2000 Instruction Format: x86 In 80x86 instructions can vary in length from 8-bits (1b) to more than 100-bits (13b) REAL MODE: –Default instruction size is 16-bits 16-bit registers & 16-bit offset fields RPOTECTED MODE: –Default instruction size is 32-bits (x386 and above) 32-bit registers & 32-bit offset fields –D-bit in descriptor specifies real or protected mode: D=0: (real-mode) 16-bit instructions, register values and addresses D=1: (protected mode) 32-bit instructions, reg. values and addresses

15 CDP ECE Spring 2000 Unconditional Jump (JMP) Short jump: 2-byte jump instr. - allows short jumps within memory locations [-128:+127] from the location following the jump instr.: –JMP SHORT Target_Label Near jump: 3-byte jump instr. - supports jumps within [- 32K:+32K] bytes from current location: –JMP Label Far jump: 5-byte instruction allowing jumps anywhere within 4Gb of address space: –JMP Label OPCODE DISP. OPCODE DISP-lowDISP-high OPCODE DISP-lowDISP-high CS low CS high

16 CDP ECE Spring 2000 Conditional Jumps A conditional Jump instruction tests a condition bit (FLAGS) and sets the IP to a specified address (given in a field of the instruction). Otherwise, IP is left unchanged and the next instruction is fetched from IP+1 (in byte addressable mode) Hence: A conditional jump is materialized by TWO instructions: –One that “compares” values or does an arith./logic op and sets bits of FLAGS accordingly, and –One that carries out the Jump based on the outcome of the operation or the bit value of selected FLAGS FLAGS used by conditional branches: –S (sign) –Z (zero) –C (carry) –P (parity) –O (overflow)

17 CDP ECE Spring 2000 The CMP is used to compare two values in signed or unsigned form and sets one or more of the previous FLAG bits based on the outcome of the comparison: CMP Operand_1 Operand_2 CMP (Comparison)

18 CDP ECE Spring 2000 Comparing Signed Integers CMP AX, BX –Sign bit (S) will be set if AX-BX has a 1 in MSB –Overflow bit (O) is set if AX-BX result is out of range (-2 15, ) JS Target_label: –Check S bit and if set then jump to Target_label (i.e. sign bit is 1) JL (Jump on less than): –JL takes the jump if (S XOR O) is 1 (jump is taken even on an overflow because overflow in a CMP or SUB instruction can happen only when first operand is a negative number and second operand is a positive number - hence their SUB becomes an addition that may overflow)

19 CDP ECE Spring 2000 Jump Instruction Semantics If num_1 & num_2 are unsigned we say num_1 is above num_2 if num_1 > num_2 (otherwise it’s below). If num_1 & num_2 are signed, num_1 is greater than num_2 if num_1 > num_2 (otherwise it’s less). Notation of jump instructions: –J = JUMP –N= Not –E= Equal –A/B= Above/below –G/L= greater/less

20 CDP ECE Spring 2000 Jump Instructions InstructionDescriptionCondition JA=JNBEJump if aboveC=0 & Z=0 Jump if not below or equal JBE=JNAJump if below or equalC=1 | Z=1 Jump if not above JAE=JNB=JNCJump if above or equalC=0 Jump if not below Jump if no Carry JB=JNA=JCJump if belowC=1 Jump if not above Jump if Carry JE=JZJump if equalZ=1 Jump if Zero (set) JNE=JNZJump if not equalZ=0 Jump if not Zero JSJump if SignS=1

21 CDP ECE Spring 2000 Jump Instructions (Cont.) InstructionDescriptionCondition JNSJump Not SignS=0 JOJump if Overflow O=1 JNOJump if No OverflowO=0 JG=JNLEJump if greaterS=0 & Z=0 Jump if not less or equal JGE=JNLJump if greater or equalS=0 Jump if not less JL=JNGEJump if lessS XOR O Jump if Not greater or eq. JLE=JNGJump if less or equalS XOR O | z=1 Jump if not greater JCXZJump if reg. CX=0CX=0

22 CDP ECE Spring 2000 Branch Instructions

23 CDP ECE Spring 2000 Case Statements

24 CDP ECE Spring 2000 Repeat/Until & While Looping

25 CDP ECE Spring 2000 Multiplication in x86

26 CDP ECE Spring 2000 Multiplication

27 CDP ECE Spring 2000 Division

28 CDP ECE Spring 2000 Stack

29 CDP ECE Spring 2000 Stack Frame Organization

30 CDP ECE Spring 2000 Stack Frame Layout


Download ppt "CDP ECE 291 -- Spring 2000 ECE 291 Spring 2000 Lecture 4: The 80x86 Instruction Set Architecture Registers-Instructions Constantine D. Polychronopoulos."

Similar presentations


Ads by Google