Thursday, May 26, 2016

8051 Program - signed to unsigned conversion 32bit

; subroutine Cr0r3
; 32-Bit 2's Complement -> magnitude / Sign Bit Conversion
;
; input: r3, r2, r1, r0 = signed word
;
; output: r3, r2, r1, r0 = magnitude
; Bit 21H = sign (21H is set if negative number)
;
; alters: acc

Cr0r3:mov a, r3 ;read high into accumulator
jb acc.7, c2a ;negative if bit 7 is 1
clr 21H ;clear sign flag if 'positive'
ret ;done
c2a:setb 21H ;set sign flag
mov a, r0 ;number is negative
cpl a ;complement
add a, #1 ;and add +1
mov r0, a
mov a, r1 ;get next byte
cpl a ;complement
addc a, #0
mov r1,a
mov a, r2 ;get next byte
cpl a ;complement
addc a, #0
mov r2,a
mov a, r3 ;get next byte
cpl a ;complement
addc a, #0
mov r3, a
ret ;done


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



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

List of topics: 8051

No comments:

Post a Comment