Assembly Alarm Clock

南笙酒味 提交于 2019-12-13 10:31:12

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/22919830/assembly-alarm-clock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!