Thursday, May 26, 2016

8051 Program - unsigned 16bit multiplication

; subroutine UMUL16
; 16-Bit x 16-Bit to 32-Bit Product Unsigned Multiply
;
; input: r1, r0 = multiplicand X
; r3, r2 = multiplier Y
;
; output: r3, r2, r1, r0 = product P = X x Y
;
; alters: acc, C

UMUL16:push B
push dpl
mov a, r0
mov b, r2
mul ab;multiply XL x YL
push acc ;stack result low byte
push b ;stack result high byte
mov a, r0
mov b, r3
mul ab ;multiply XL x YH
pop 00H
add a, r0
mov r0, a
clr a
addc a, b
mov dpl, a
mov a, r2
mov b, r1
mul ab ;multiply XH x YL
add a, r0
mov r0, a
mov a, dpl
addc a, b
mov dpl, a
clr a
addc a, #0
push acc ;save intermediate carry
mov a, r3
mov b, r1
mul ab ;multiply XH x YH
add a, dpl
mov r2, a
pop acc ;retrieve carry
addc a, b
mov r3, a
mov r1, 00H
pop 00H ;retrieve result low byte
pop dpl
pop B
ret


Source: Maths Subroutines for the 8051 microcontroller, W.G.Marshall 2002



Related topics:
8051 Program - signed 8bit multiplication   |   8051 Program - unsigned 8bit multiplication   |   8051 Program - signed 8bit x 16bit multiplication   |   8051 Program - signed 16bit multiplication   |   8051 Program - signed 16bit multiply Accumulate   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment