Tutorial Microcontroller MCS-51 ATMEL ISP

Pelatihan Mikrokontroller

 

Microcontroller Kits

Programmer and Target 89s51

Simple Mikrokontroller 89s51 Trainer


Standart
Mikrokontroller 89s51 Trainer

Super Mikrokontroller Trainer 89s51

 

 

 

 

BACK

Subroutine Addition for 8051 Microcontroller


;====================================================================
; 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
;====================================================================
; subroutine ADD32
; 32-Bit Signed (2's Complement) Addition
;
; input: r3, r2, r1, r0 = X
; r7, r6, r5, r4 = Y
;
; output: r3, r2, r1, r0 = signed sum S = X + Y
; Carry C is set if the result (S) is out of range
;
; alters: acc, C, OV
;====================================================================
ADD32:     anl PSW, #0E7H ; Register Bank 0
           mov a, r0 ; load X low byte into acc
           add a, r4 ; add Y low byte
           mov r0, a ; save result
           mov a, r1 ; load X next byte into acc
           addc a, r5 ; add Y next byte with carry
           mov r1, a ; save result
           mov a, r2 ; load X next byte into acc
           addc a, r6 ; add Y next byte
           mov r2, a ; save result
           mov a, r3 ; load X high byte into acc
           addc a, r7 ; add Y high byte with carry
           mov r3, a
           mov C, OV
           ret

Comments, questions and discussion about this topic

BACK