简体   繁体   中英

Printing 3-digit Hex numbers in Arm 7 Assembly

Alright guys I need your help on this program. I am trying to print out 3-digit hex numbers increasing by 345 each time. I understand in assembly I am supposed to print each part of the hex number individually. I would do this by doing shifts "lsr", yet I am getting a wrong number for the first part of the number. The first number after 0 should be 149 (345 in decimal) but I am getting A59 (2649 in decimal).

heres the my code

.globl _start
_start:
    ldr r4,=0x101f1000
    mov r0, #0x00
    lsl r0, #4
    add r0, #0
    mov r5, #0xBB
    lsl r5, #4
    add r5, r5, #8
my_loop:
    cmp r0, r5
    bgt my_exit
    lsr r1, r0, #6
    and r1, r1, #0x0000000f
    cmp r1, #10
    addlt r1, r1, #48
    addge r1, r1, #55
    str r1, [r4]
    lsr r1, r0, #4
    and r1, r1, #0x0000000f
    cmp r1, #10
    addlt r1, r1, #48
    addge r1, r1, #55
    str r1, [r4]
    lsr r1, r0, #0
    and r1, r1, #0x0000000f
    cmp r1, #10
    addlt r1, r1, #48
    addge r1, r1, #55
    str r1, [r4]
    mov r1, #13 
    str r1, [r4]        
    mov r1, #10     
    str r1, [r4]        

    add r0, r0, #99
    add r0, r0, #99
    add r0, r0, #99
    add r0, r0, #48
    b my_loop

my_exit:

我只是发现我的移位不正确,应该是8位而不是6位。还要感谢@Michael给出了相同的答案。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM