; subroutine ADD16
; 16-Bit Signed (2's Complement) Addition
;
; input: r1, r0 = X
; r3, r2 = Y
;
; output: r1, r0 = signed sum S = X + Y
; Carry C is set if the result (S) is out of range
;
; alters: acc, C, OV
ADD16: anl PSW, #0E7H ;Register Bank 0
mov a, r0 ;load X low byte into acc
add a, r2 ;add Y low byte
mov r0, a ;put result in Z low byte
mov a, r1 ;load X high byte into acc
addc a, r3 ;add Y high byte with carry
mov r1, a ;save result in Z high byte
mov C, OV
ret
Source: Maths Subroutines for the 8051 microcontroller, W.G.Marshall 2002
Related topics:
8051 Program - signed 32bit addition | 8051 Program - signed 16bit subtraction | 8051 Program - signed 32bit subtraction | 8051 Program - signed 8bit multiplication | 8051 Program - unsigned 8bit multiplication | 8051 Program - memory subroutines | 8051 Program - math subroutines | 8051 Program - conversion subroutines
List of topics: 8051
No comments:
Post a Comment