Thursday, May 26, 2016

8051 Program - signed 32bit division

; subroutine DIV32
; 32-Bit / 16-Bit to 32-Bit Quotient & remainder signed Divide
; 2's Complement Format
;
; input: r3, r2, r1, r0 = Dividend X
; r5, r4 = Divisor Y
;
; output: r3, r2, r1, r0 = quotient Q of division Q = X / Y
; r7, r6, r5, r4 = remainder
; Carry C is set if Y = 0, i.e. divide by 0 attempted
;
; calls: UDIV32, Cr0r3, Cr4r5, Mr0r3
;
; alters: acc, flags, Bits 21H & 22H

DIV32:anl PSW, #0E7H ;Register Bank 0
mov a, r4 ;get divisor high byte
orl a, r5 ;OR with low byte
jnz div32_OK ;divisor OK if not 0
setb C ;else, overflow
ret
div32_OK:acall Cr0r3 ;2's comp -> Mag/Sign
acall Cr4r5 ;2's comp -> Mag/Sign
acall UDIV32
acall Mr0r3 ;Mag/Sign -> 2's Comp
clr C ;divisor is not 0
ret ;done


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



Related topics:
8051 Program - signed 8bit division   |   8051 Program - unsigned 8bit division   |   8051 Program - signed 16bit division   |   8051 Program - unsigned 16bit division   |   8051 Program - unsigned 32bit division   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment