Professional Documents
Culture Documents
(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
;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.
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 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)