SAMPLE PROGRAM:
LXI H,0101
LXI D,3520
DAD D
HLT
//ANSWER IN HL PAIR 3621
Program: 16 bit addition
(C050H) = 15H
(C051H) = 1CH
(C052H) = B7H
(C053H) = 5AH
Result = 1C15 + 5AB7H = 76CCH
(C054H) = CCH
(C055H) = 76H
Program 1:
LHLD C050H : Get first I6-bit number in HL
XCHG : Save first I6-bit number in DE
LHLD C052H : Get second I6-bit number in HL
MOV A, E : Get lower byte of the first number
ADD L : Add lower byte of the second number
MOV L, A : Store result in L register
MOV A, D : Get higher byte of the first number
ADC H : Add higher byte of the second number with CARRY
MOV H, A : Store result in H register
SHLD C054H : Store I6-bit result in memory locations C054H and C0C5H.
HLT : Terminate program execution
Program: 16 bit subtraction
(C050H) = 45H
(C051H) = 52H
(C052H) = 14H
(C053H) = 12H
Result = 5245H - 1214H = 4031H
(C054H) = 31H
(C055H) = 40H
Program 2:
LHLD C050H : Get first I6-bit number in HL
XCHG : Save first I6-bit number in DE
LHLD C052H : Get second I6-bit number in HL
MOV A, E : Get lower byte of the first number
SUB L : Sub lower byte of the second number
MOV L, A : Store result in L register
MOV A, D : Get higher byte of the first number
SBB H : Sub higher byte of the second number with BORROW
MOV H, A : Store result in H register
SHLD C054H : Store I6-bit result in memory locations C054H and C0C5H.
HLT : Terminate program execution
0 Comments