; subroutine Mr0r1
; 16-Bit magnitude / Sign Bit -> 2's Complement Conversion
;
; input: r1, r0 = magnitude
; Bits 21H & 22H = sign bits of operands X and Y
; (set if negative)
;
; output: r1, r0 = signed word
;
; alters: acc, C
Mr0r1: jb 21H, Mr0r1b ;test X sign
jb 22H, Mr0r1a ;test Y sign
ret
Mr0r1b: jnb 22H, Mr0r1a
ret
Mr0r1a: 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
ret
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 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