Thursday, May 26, 2016

8051 Program - signed 8bit x 16bit multiplication

; subroutine MUL816
; 8-Bit x 16-Bit to 32-Bit Product signed Multiply
; 2's Complement format
;
; input: r0 = multiplicand X
; r3, r2 = multiplier Y
;
; output: r3, r2, r1, r0 = product P = X x Y (r3 = sign extension)
;
; calls: Cr0, Cr2r3, Mr0r3
;
; alters: acc, C, Bits 21H & 22H

MUL816:push b
anl PSW, #0E7H ;Register Bank 0
acall Cr0 ;2's comp -> Mag/Sign
acall Cr2r3 ;2's comp -> Mag/Sign
mov a, r0 ;load X low byte into acc
mov b, r2 ;load Y low byte into B
mul ab ;multiply
push acc ;stack result low byte
push b ;stack result high byte
mov a, r0 ;load X into acc again
mov b, r3 ;load Y high byte into B
mul ab ;multiply
pop 00H ;recall X*YL high byte
add a, r0 ;add X*YL high and X*YH low
mov r1, a ;save result
clr a ;clear accumulator
addc a, b ;a = b + carry flag
mov r2, a ;save result
pop 00H ;get low result
mov r3, #0
acall Mr0r3 ;Mag/Sign -> 2's Comp
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 16bit multiplication   |   8051 Program - unsigned 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