You are on page 1of 4

16 Bit Multiplication

(A)Internal memory Write a program to multiply two 16-bit numbers.(Data:6230h & 432Eh)
MOV R6,#62h MOV R7,#30h MOV R4,#43h MOV R5,#2Eh LCALL MUL16 END MUL16: ;Multiply R5 by R7 MOV A,R5 MOV F0H,R7 MUL AB MOV R2,F0H MOV R3,A ;Multiply R5 by R6 MOV A,R5 MOV F0H,R6 MUL AB ADD A,R2 MOV R2,A MOV A,F0H ADDC A,#00h MOV R1,A MOV A,#00h ADDC A,#00h MOV R0,A ;Move R5 back into the Accumulator ;Move R6 into B ;Multiply the two values ;Add the lowbyte into value in R2 ;Move the resulting value back into R2 ;Move the high-byte into the accumulator ;Add zero (plus the carry, if any) ;Move the resulting answer into R1 ;Load the accumulator with zero ;Add zero (plus the carry, if any) ;Move the resulting answer to R0. ;Move the R5 into the Accumulator ;Move R7 into F0H ;Multiply the two values ;Move B (the high-byte) into R2 ;Move A (the low-byte) into R3 ;Load 62h into register R6 ;Load 30h into register R7 ;Load 43h into register R4 ;Load 2Eh into register R5 ;Call subroutine for 16bit multiplication ;End of the program

Prepared by: Korat Uday A(be 3rd _ldce(EC))

;Multiply R4 by R7 MOV A,R4 MOV F0H,R7 MUL AB ADD A,R2 MOV R2,A MOV A,F0H ADDC A,R1 MOV R1,A MOV A,#00h ADDC A,R0 MOV R0,A ;Multiply R4 by R6 MOV A,R4 MOV F0H,R6 MUL AB ADD A,R1 MOV R1,A MOV A,F0H ADDC A,R0 MOV R0,A RET ;Move R4 back into the Accumulator ;Move R6 into B ;Multiply the two values ;Add the low-byte into the value in R1 ;Move the resulting value back into R1 ;Move the high-byte into the accumulator ;Add it to the value already in R0 + carry ;Move the resulting answer back to R0 ;Return(answer is now in R0, R1, R2,R3) ;Move R4 into the Accumulator ;Move R7 into B ;Multiply the two values ;Add the low-byte into value in R2 ;Move the resulting value back into R2 ;Move the high-byte into the accumulator ;Add the current value of R1 (plus carry) ;Move the resulting answer into R1. ;Load the accumulator with zero ;Add the current value of R0 (plus carry) ;Move the resulting answer to R1.

Prepared by: Korat Uday A(be 3rd _ldce(EC))

(B) external memory


ORG 00H CALL TRANSFER_IN CALL MUL_16 CALL TRANSFER_OUT TRANSFER_IN: MOV DPTR, #ADD_FIRST BYTE MOV R0, #04H MOV R1, #04H HERE: MOVX A, @DPTR MOV @R0, A INC R0 INC DPTR DJNZ R1, HERE RET MUL_16: ;Multiply R5 by R7 MOV A,R5 MOV F0H,R7 MUL AB MOV R2,F0H MOV R3,A ;Multiply R5 by R6 MOV A,R5 MOV F0H,R6 MUL AB ADD A,R2 MOV R2,A MOV A,F0H ADDC A,#00h MOV R1,A MOV A,#00h ADDC A,#00h ;Move R5 back into the Accumulator ;Move R6 into B ;Multiply the two values ;Add the lowbyte into value in R2 ;Move the resulting value back into R2 ;Move the high-byte into the accumulator ;Add zero (plus the carry, if any) ;Move the resulting answer into R1 ;Load the accumulator with zero ;Add zero (plus the carry, if any) ;Move the R5 into the Accumulator ;Move R7 into F0H ;Multiply the two values ;Move B (the high-byte) into R2 ;Move A (the low-byte) into R3

Prepared by: Korat Uday A(be 3rd _ldce(EC))

MOV R0,A ;Multiply R4 by R7 MOV A,R4 MOV F0H,R7 MUL AB ADD A,R2 MOV R2,A MOV A,F0H ADDC A,R1 MOV R1,A MOV A,#00h ADDC A,R0 MOV R0,A ;Multiply R4 by R6 MOV A,R4 MOV F0H,R6 MUL AB ADD A,R1 MOV R1,A MOV A,F0H ADDC A,R0 MOV R0,A RET

;Move the resulting answer to R0.

;Move R4 into the Accumulator ;Move R7 into B ;Multiply the two values ;Add the low-byte into value in R2 ;Move the resulting value back into R2 ;Move the high-byte into the accumulator ;Add the current value of R1 (plus carry) ;Move the resulting answer into R1. ;Load the accumulator with zero ;Add the current value of R0 (plus carry) ;Move the resulting answer to R1.

;Move R4 back into the Accumulator ;Move R6 into B ;Multiply the two values ;Add the low-byte into the value in R1 ;Move the resulting value back into R1 ;Move the high-byte into the accumulator ;Add it to the value already in R0 + carry ;Move the resulting answer back to R0 ;Return(answer is now in R0, R1, R2,R3)

Answer stored in r0(msb),r1,r2,r3(lsb)


TRANSFER_OUT: MOV DPTR, #ADD_ANSBYTE SETB PSW.3 MOV RO, #00H MOV R1, #04H THERE: MOV A, @R0 MOVX @DPTR, A INC R0 INC DPTR DJNZ R1, THERE
Prepared by: Korat Uday A(be 3rd _ldce(EC))

You might also like