Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

timer - Assembly Alarm Clock

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...