MULTIPLICATION OF TWO 16-BIT NUMBERS

ALGORITHM:
1. START
2. The first 16-bit number, which is at 2000H address, is loaded to HL pair.
3. The HL pair value is moved to stack pointer (SP) register whixh is also 16-bit register.
4. The second 16-bit number, which is at 3000H address, is loaded to HL pair.
5. The HL pair value is exchanged with DE pair. (H<->D, L<->E)
6. The two 16-bit value register (HL and BC) set to zero.
7. Here, SP value is addend and DE value is counter.
8. Then, SP value is repeatedly added to HL until DE reaches zero.
9. Lower 16-bit is at HL pair and Higher 16-bit at BC pair if necessary.
10. For counter DE to test whether it is zero or not, we can only test for 8-bit register only. So, two 8-bit values D and E are logically ORed. If any one bit is non-zero, it yields non-zero, otherwise zero.
11. Finally, lower 16-bit is stored at 2008H and higher 16-bit at 200AH address.
12. STOP.
PROGRAM:
LHLD 2000H 
SPHL 
LHLD 3000H 
XCHG 
LXI H,0000H 
LXI B,0000H 
NEXT: DAD SP 
JNC AHEAD 
INX B 
AHEAD: DCX D 
MOV A,E 
ORA D 
JNZ NEXT 
SHLD 2008H 
MOV L,C 
MOV H,B 
SHLD 200AH 
HLT

No comments:

Post a Comment