Im tasked to increment by 3 from 0150 to 9999 using MCU 8051
org 0000h
<code>mov r5, #01
mov r4, #50
</code>
<code>mov r5, #01
mov r4, #50
</code>
mov r5, #01
mov r4, #50
start:
<code>mov a, #8
lcall cmdwr
</code>
<code>mov a, #8
lcall cmdwr
</code>
mov a, #8
lcall cmdwr
solving:
<code>jmp lowerbyte
</code>
<code>jmp lowerbyte
</code>
jmp lowerbyte
kill:
<code>ljmp end
</code>
<code>ljmp end
</code>
ljmp end
higherbyte:
<code>clr c
mov a, r5
inc a
mov r5, a
mov r3, a
subb a, #100 ; check if past 9999
jnc kill
mov r4, #11111110B
</code>
<code>clr c
mov a, r5
inc a
mov r5, a
mov r3, a
subb a, #100 ; check if past 9999
jnc kill
mov r4, #11111110B
</code>
clr c
mov a, r5
inc a
mov r5, a
mov r3, a
subb a, #100 ; check if past 9999
jnc kill
mov r4, #11111110B
lowerbyte:
<code>mov a, r4
add a, #3 ;increment by 3
mov r4, a
mov r1, a
subb a, #100
jnc higherbyte
mov a, r5
mov r3, a
</code>
<code>mov a, r4
add a, #3 ;increment by 3
mov r4, a
mov r1, a
subb a, #100
jnc higherbyte
mov a, r5
mov r3, a
</code>
mov a, r4
add a, #3 ;increment by 3
mov r4, a
mov r1, a
subb a, #100
jnc higherbyte
mov a, r5
mov r3, a
It should increment the lowerbyte by 3 and when it exceeds 99 it would increment the higherbyte and would still show the sum of the previous increment at the lower byte i.e. (0599+3 = 0502), instead at certain numbers (0699+3 = 0701)
New contributor
Desii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.