Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a question. If my alarmS == 60 i need to switch inc alarmM and reset the alarmS but I have a question

 increment_alarm_second:
inc alarmS                          ; increment alarmS
cpi alarmS  , 0x5A  ; 0x3C          ; Compare alarmS to 60
breq increment_alarm_minute         ; If true, jump incMinute
swap alarmS                         ; swap here to save registers ( swap nibbles )
cpi alarmS  , 0xA0                  ; compares alarmS register to an inverted 10
brlo endIncSecal                    ; branch if lower then an inverted 10 to endIncSecal

    incSecTenal:            
        andi alarmS, 0x0F           ; does an AND + increment on the alarmS register
        inc alarmS                  ; increments the alarmS register
        swap alarmS                 ; swaps alarm_s register
    ret                             ; returns from the calll

endIncSecal:                        
swap alarm_s                        ; swap back
ret

why is cpi alarmS , 0x5A ? and not 0x3C which is 60..

after that we swap the nibbles and compare it with , 0xA0?? why is this?

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
172 views
Welcome To Ask or Share your Answers For Others

1 Answer

The snippet is keeping track of the digits of the seconds separately. That is, the first nibble is the multiple of 10 seconds. The second nibble is the remainder.

When the second nibble reaches 10, it is cleared and the first nibble incremented.

If the value reaches "50 and 10" (that is, 60 seconds) then it is cleared and the minutes incremented.

The major problem with this snippet is that all this needs to be explained in a comment in the code. It is unexpected enough to demand it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...