SAP-3
- architectural differences with SAP-1, SAP-2
- registers and move instructions
- arithmetic instructions and carry flag
- multi-precision addition and subtraction
- rotate and compare
- arithmetic, logic immediate instructions
- jump instructions
- 16-bit register pairing and 16-bit load, arithmetic
- indirect instructions
Architectural Changes from SAP-2
- more registers (SP, D, E, H, L, F)
- carry flag and corresponding arithmetic and rotate instructions
- parity flag
- compare instruction
- jump on all the flags
- 16-bit register pairing and 16-bit load, arithmetic
- indirect instructions
- stack instructions, including CALL, and conditional calls
- (8085 equivalent)
Registers and Move instructions
- registers D, E, H, L, SP, and F
- DE and HL can be a 16-bit pair
- AF can be a 16-bit pair (but not for arithmetic)
- HL can be used for indirect instructions
- F is the flag register: stores Z, sign, Carry, Parity
- MOV moves between any pair of (8-bit) registers
- MVI loads an 8-bit value into any register (except F)
Arithmetic instructions, Carry flag
- carry flag stores carry from most recent addition or subtraction
- ADD, SUB set carry flag, don't use it
- ADC, SBB both use and set carry flag
Multi-precision addition and subtraction
MOV A, L
ADD C
MOV L, A
MOV A, H
ADC B
MOV H, A
- subtraction is analogous
- in-class exercise: using 8-bit binary addition and subtraction,
compute the following 16-bit value: 300 + 501 - 652. Hex
equivalents are: 300 = 12CH, 501 = 1F5H, 652 = 28CH.
Rotate and Compare
- increment and decrement do not set the carry flag (but do
set Z and S)
- Rotate All Left: MSB goes to carry, carry goes to LSB
- Rotate All Right: LSB goes to carry, carry goes to MSB
- Rotate Left with Carry: MSB goes to carry and to LSB
- Rotate Right with Carry: LSB goes to carry and to MSB
- Rotate Left can be used to multiply by 2, but shift left (which shifts
in 0 bits) works better for negative numbers
- Rotate Right can be used to divide by 2, but shift right works
better for positive number, and shift right arithmetic (which shifts
in copies of the most significant bit) works well for both positive
and negative numbers
- CMP subtracts and sets Z, does not save the result
Immediate arithmetic/logic instructions
- logic: ANI, ORI, XRI
- arithmetic: ADI, ACI, SUI, SBI, CPI
Jump and 16-bit Instructions
- SAP-2: JMP, JZ, JNZ, JM
- SAP-3: same, plus JP, JC, JNC, JPE, JPO
- LXI (B, D, or H) loads an immediate 16-bit value
- DAD (double Add) loads BC, DE, or HL to HL (using HL as
accumulator)
- INX or DCX
Indirect addressing
- how would we code x = a [10]?
- assume &a == 0x9ABC, so if a is an array
of bytes (chars), we need to load the byte at location
&(a[10]) == 0x9AC6
- self-modifying code:
- generate instructions to load 0x9AC6 into a register
- store the instructions somewhere in memory
- store a RET instruction after the load instructions
- "call" the newly generated instructions
- indexing: store the value 0x9ABC in a register
(HL), add 10, and execute MOV reg, M
Stack
- initialized with, e.g. LXI SP, 2100H
- push: puts a 16-bit value onto the stack
- places the high byte at SP-1
- places the low byte at SP-2
- places SP-2 into SP
- pop: takes a 16-bit value from the stack
- puts the byte at SP int the low register
- puts the byte at SP+1 int the high register
- places SP+2 into SP