Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
16-Bit Addressing Registers (no 8-bit access) FLAGS Register (status flags – one bit/flag)
IP Instruction Pointer • 16-bit reg, but only 4 bits have meaning
SP Stack Pointer • treat as individual bits, not 16-bit value
BP Base Pointer • ignore unused bits
– CF Carry Flag
SI Source Index
– SF Sign Flag data
DI Destination Index – OF Overflow Flag manipulation
– IF Interrupt Flag & conditional
control flow
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 3 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 4
94201.lecture9 -12-processor 94201.lecture9 -12-processor
IR Instruction Register
} until HLT instruction has been executed
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 5 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 6
94201.lecture9 -12-processor 94201.lecture9 -12-processor
1
P-86 Execution Cycle (contd) P86 Instruction Cycle (contd)
FFFF
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 7 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 8
94201.lecture9 -12-processor 94201.lecture9 -12-processor
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 9 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 10
94201.lecture9 -12-processor 94201.lecture9 -12-processor
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 11 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 12
94201.lecture9 -12-processor 94201.lecture9 -12-processor
2
Data Transfer Example Register Addressing Mode
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 13 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 14
94201.lecture9 -12-processor 94201.lecture9 -12-processor
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 17 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 18
94201.lecture9 -12-processor 94201.lecture9 -12-processor
3
Manipulating I/O Ports I/O Port Example
§ MOV allows only register and memory § For now: OUT [DX], AL
operands • the 8 -bit value in AL is written to the I/O port
addressed by the contents of DX (indirect mode!)
§ so . . . what accesses I/O ports? § Display character at the “current” cursor position:
• IN read a value from a port
• write 7-bit ASCII encoded char to port 04E9H
• OUT write a value to a port
• must set up DX to point to I/O port
§ IN / OUT: always use AL (or AX) and [DX] • must set up AL to contain char
• write: display char and “ advance” cursor
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 19 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 20
94201.lecture9 -12-processor 94201.lecture9 -12-processor
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 23 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 24
94201.lecture9 -12-processor 94201.lecture9 -12-processor
4
Operand Compatibility (contd) Data Manipulation Instructions
§ need syntax to remove ambiguity § use state variable values to compute new values
§ qualify off-processor access using: § modify state variables to hold results (incl FLAGS)
WORD PTR word pointer – 16-bit operand ADD dest, src
BYTE PTR byte pointer – 8-bit operand à dest := dest + src (bitwise add)
e.g. no ambiguity with: § dest is both a source and destination operand
MOV BYTE PTR [ BX ], 1 ;8 bit dest § also modifies FLAGS as part of instruction execution:
§ ZF := 1 if-and-only-if (iff) result = 0
MOV WORD PTR [1234H], 0 ;16 bit dest
§ SF := 1 iff msbit of result = 1 (sign = negative)
§ CF := 1 iff carry out of msbit
§ OF := 1 iff result overflowed signed capacity
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 25 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 26
94201.lecture9 -12-processor 94201.lecture9 -12-processor
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 27 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 28
94201.lecture9 -12-processor 94201.lecture9 -12-processor
5
More Data Manipulation Instructions Control Flow Instructions
32-bit dividend See Instruction Reference (posted) for more complete list
DIV src 16-bit divisor (src)
§ for 16-bit src: of instructions – includes effects on FLAGS !!
• divide src into 32-bit value obtained by concatenating § execution may change value in IP
DX and AX (written DX:AX) § changes address for fetch of next instruction
• AX := DX:AX ÷ src (unsigned divide)
• DX := DX:AX mod src (unsigned modulus)
• flags are undefined after DIV
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 35 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 36
94201.lecture9 -12-processor 94201.lecture9 -12-processor
6
Conditional Jumps (contd) Conditional Jumps (contd)
CMP dest, src (Compare)
§ often condition and “not” condition are valid instr § performs dest – src and sets FLAGS
§ e.g. JZ dest (Jump Zero) § often useful to think of combination as:
JNZ dest (Jump Not Zero) CMP dest, src
JC dest (Jump Carry) Jxx jmpdest
• more too! (Instruction Reference!) § jump is taken if “ dest xx src” condition holds
§ Conditional Jump often follows CMP § Some conditions for xx:
CMP AL, 10 § JE Jump Equal (opposite is JNE)
JL LessThanTen § JL Jump Less Than (JNL)
. . . ; some code here § JLE Jump Less Than or Equal (JNLE)
LessThanTen: § JG Jump Greater Than
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 37 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 38
94201.lecture9 -12-processor 94201.lecture9 -12-processor
§ Conditional jump limitation: uses 8-bit signed § One possible workaround if distance is
relative offset! 8 bits, ‘sign extended to greater than 127 bytes (but not the only
16 bits’
IP := IP + offset one!):
§ can’t jump very far! – 128 ßà +127 bytes JNL Continue 16-bit relative offset
§ example: JL Less JMP Less
some code maximum possible Continue: lots of distance >> 127 bytes
here distance = 127 bytes code here
Less: Less:
MOV . . . MOV . . .
01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 41 01 Oct-01 94.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 42
94201.lecture9 -12-processor 94201.lecture9 -12-processor