## Saturday, April 30, 2016

### 8051 Program – multiplication 16bit

``` ;16bit multiplication ; * R6 R7 ; * R4 R5 ; = R0 R1 R2 R3 ; Multiply R5 by R7, leaving the 16-bit result in R2 and R3 ; Multiply R5 by R6, adding the 16-bit result to R1 and R2 ; Multiply R4 by R7, adding the 16-bit result to R1 and R2 ; Multiply R4 by R6, adding the 16-bit result to R0 and R1 ORG 0H MAIN: MOV R6,#62H ;Load the first value into R6 and R7 MOV R7,#30H MOV R4,#43H ;Load the second value into R4 and R5 MOV R5,#2EH LCALL MUL_16 SJMP MAIN MUL_16: ;Multiply R5 by R7 MOV A,R5 ;Move the R5 into the Accumulator MOV B,R7 ;Move R7 into B MUL AB ;Multiply the two values MOV R2,B ;Move B (the high-byte) into R2 MOV R3,A ;Move A (the low-byte) into R3 ;Multiply R5 by R6 MOV A,R5 ;Move R5 back into the Accumulator MOV B,R6 ;Move R6 into B MUL AB ;Multiply the two values ADD A,R2 ;Add the low-byte into the value already in R2 MOV R2,A ;Move the resulting value back into R2 MOV A,B ;Move the high-byte into the accumulator ADDC A,#00h ;Add zero (plus the carry, if any) MOV R1,A ;Move the resulting answer into R1 MOV A,#00h ;Load the accumulator with zero ADDC A,#00h ;Add zero (plus the carry, if any) MOV R0,A ;Move the resulting answer to R0. ;Multiply R4 by R7 MOV A,R4 ;Move R4 into the Accumulator MOV B,R7 ;Move R7 into B MUL AB ;Multiply the two values ADD A,R2 ;Add the low-byte into the value already in R2 MOV R2,A ;Move the resulting value back into R2 MOV A,B ;Move the high-byte into the accumulator ADDC A,R1 ;Add the current value of R1 (plus any carry) MOV R1,A ;Move the resulting answer into R1. MOV A,#00h ;Load the accumulator with zero ADDC A,R0 ;Add the current value of R0 (plus any carry) MOV R0,A ;Move the resulting answer to R1. ;Multiply R4 by R6 MOV A,R4 ;Move R4 back into the Accumulator MOV B,R6 ;Move R6 into B MUL AB ;Multiply the two values ADD A,R1 ;Add the low-byte into the value already in R1 MOV R1,A ;Move the resulting value back into R1 MOV A,B ;Move the high-byte into the accumulator ADDC A,R0 ;Add it to the value already in R0 (plus any carry) MOV R0,A ;Move the resulting answer back to R0 RET END ```

Related topics:
8051 Program - arithmetic operation 8bit   |   8051 Program - addition 8bit   |   8051 Program - subtraction 8bit   |   8051 Program - multiplication 8bit   |   8051 Program - division 8bit   |   8051 Program - addition 16bit   |   8051 Program - subtraction 16bit   |   8051 Program - division 16bit   |   8051 Program - addition multibyte   |   8051 Program - multiplication 16bit by 8bit   |   8051 Program - addition 8bit 2digit bcd   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051