![]() |
|||
Microcontroller Kits Simple
Mikrokontroller 89s51 Trainer
Super
Mikrokontroller Trainer 89s51
|
Subroutine Subbtraction for 8051 Microcontroller
;==================================================================== SUB16: anl PSW, #0E7H ; Register Bank 0
mov a, r0 ; load X low byte into acc
clr C ; clear carry flag
subb a, r2 ; subract Y low byte
mov r0, a ; put result in Z low byte
mov a, r1 ; load X high into accumulator
subb a, r3 ; subtract Y high with borrow
mov r1, a ; save result in Z high byte
mov C, OV
ret
;==================================================================== ; subroutine SUB32 ; 32-Bit Signed (2's Complement) subtraction ; ; input: r3, r2, r1, r0 = X ; r7, r6, r5, r4 = Y ; ; output: r3, r2, r1, r0 = signed difference D = X - Y ; Carry C is set if the result (D) is out of range. ; ; alters: acc, C, OV ;==================================================================== SUB32: anl PSW, #0E7H ; Register Bank 0
mov a, r0 ; load X low byte into acc
clr C ; clear carry flag
subb a, r4 ; subract Y low byte
mov r0, a ; put result in Z low byte
mov a, r1 ; repeat with other bytes...
subb a, r5
mov r1, a
mov a, r2
subb a, r6
mov r2, a
mov a, r3
subb a, r7
mov r3, a
mov C, OV ; set C if external borrow
ret
Comments, questions and discussion about this topic
|
||