Friday, September 9, 2011

Statement: Multiply two 8 bit numbers stored in memory location D000H and D001H.
Store the result in memory locations E000H and E001H.

LDA D000H
MOV E,A
LDA D001H
MOV C,A
MVI D,00H
LXI H,0000H
BACK:
DAD D
DCR C
JNZ BACK
SHLD E000H
HLT

Explanation: 
[Remember: If we want to multiply 4 and 3 then 4*3= 4+4+4=3+3+3+3=12. In this program we are going to multiply two numbers using this method.]

First of all load the data (number) in accumulator stored at memory location D000H  using LDA instruction. Copy the data in register E. After that load accumulator with the data(another number) stored at memory location D001H and copy it in register C.

MVI D,00H instruction is used to clear the data of register D.(if there is any)
The same goes with HL register pair.

'BACK' Loop:

DAD instruction is used to add the specified register pair to HL pair. Here, we have D=00H and E=number or data which will be added to HL pair.Another number stored in register C works as a counter so we have decremented it by 1. After that if the value of register C is not zero then it will again jump to the 'Back' loop. So, 'number 1' will be added to itself,(How many times???) 'number 2' times.

When the value of C register becomes 00H it will jump out of the loop. HL pair will be containing the final result of multiplication, and it is stored at memory location E000H and E001 H using SHLD instruction.

HLT stands for 'stop'. :-)

No comments:

Post a Comment