Sap 3 Architecture
Sap 3 Architecture
SAP3 instruction set includes all the SAP 2 instructions plus new instructions. SAP 3 Programming Model
A FC SL B D H C E L F
CARRY FLAG INSTRUCTIONS Note: There are two instructions that can be used to control the carry flag. 1. STC - SET CARRY - will set the CY flag if it is not set e.g. if CY=0, STC produces CY=1 2. CMC - COMPLEMENT THE CARRY - complements the value of CY
Note: The additional CPU registers, D, E, H and L are used for more efficient data processing. The F register stores flag bits: S (sign flag), Z (zero flag) and others. ADVANTAGE OF MORE CPU REGISTERS 1. Programs can run faster 2. Simplifies program writing ARITHMETIC INSTRUCTIONS Example 1:
ADD INSTRUCTIONS
ADD REG
Answer:
CY=0 A=1111 1001
Example 2: Note: CY = CARRY if operation is ADD CY = CARRY if operation is SUB Note: The 8-bit sum S7S0 is stored in the accumulator. The CY is stored in a special FF called CARRY FLAG. CY A7 A6 A5 A2 A1 A0
Answer:
CY= 1 A=0000 0000
Note: The CY flag acts like the next higher bit of the accumulator, i.e. CY = AB
Example 2:
ADD REG
Example 1:
Answer:
CY=1 A=1111 1010
Answer:
CY=0 A=1001 0110 SBB INSTRUCTIONS (SBB = Subtract with borrow) Note: It subtracts the contents of a specified register and the CY flag from the accumulator contents. SUB INSTRUCTIONS Example 1:
SUB REG
Example 1:
Answer:
CY=0 A=1111 1100
Answer:
CY=0 A=0000 1110
INCREMENTS
INR REG
Note: The INR instruction has no effect on the carry flag, but it does affect the sign flags and zero flags. Example 1:
CY
MSB
LSB
B = 1111 1111, and The initial flags are S=1, Z=0, CY=0
Answer:
B = 0000 0000 S=0, Z=1, CY=0
CY = 1 A = 0111 0100
Answer:
CY=0 A = 1110 1001
DECREMENTS
DEC REG
Example 1:
CY
MSB
LSB
CY = 1 A = 0111 0100
Answer:
CY=0 A = 1011 1010
MULTIPLY AND DIVIDE BY 2 Uses of rotate instructions: 1. Parallel to serial and serial to parallel conversion of data. 2. Has the effect of multiplying or dividing the accumulator contents by a factor of 2. Note: With the carry flag reset, a RAL has the effect of multiplying by 2, while the RAR divides by 2.
CY
MSB
LSB
Note: This instruction will rotate the contents of the accumulator to the left and the MSB is saved in the CY flag. Example 1:
CY = 1 A = 0111 0100
Answer:
CY=0 A = 1110 1000
Example 1:
RAL
CY = 0 A = 0000 0111
Answer:
CY=0 A = 0000 1110 ROTATE RIGHT WITH CARRY (RRC)
Example 2:
CY
MSB
LSB
RAL
CY = 0 A = 0010 0001
Answer:
CY=0 A = 0100 0010
CY = 1 A = 0111 0100
Answer:
CY=0 A = 0011 1010
Example 3:
Example program:
RAR
CY = 0 A = 0001 1000
Answer:
CY=0 A = 0000 1100
Show a SAP 3 program that adds 700 and 400, with the final answer stored in the H ad L registers.
INSTRUCTION
Example 3:
RAR
CY = 0 A = 0000 1100
Answer:
CY=0 A = 0000 0110
MVI 00H MVI 02H MVI BCH MVI O3H MVI 84H ADD ADD MOV MVI 00H
A, B, C, D, E, C E L, A A,