Thursday, May 26, 2016

8051 Program - unsigned to signed conversion 32bit

; subroutine Mr0r3
; 32-Bit magnitude / Sign Bit -> 2's Complement Conversion
;
; input: r3, r2, r1, r0 = magnitude
; Bits 21H & 22H = sign bits of operands X and Y
; (set if negative)
;
; output: r3, r2, r1, r0 = signed word
;
; alters: acc, C

Mr0r3:jb 21H, Mr0r3b ;test X sign
jb 22H, Mr0r3a ;test Y sign
ret
Mr0r3b:jnb 22H, Mr0r3a
ret
Mr0r3a:mov a, r0 ;negate number
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 - signed to unsigned conversion 32bit   |   8051 Program - unsigned to signed conversion 8bit   |   8051 Program - unsigned to signed conversion 16bit   |   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