Printing 3-digit Hex numbers in Arm 7 Assembly

0

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:
assembly
arm
hex
asked on Stack Overflow Apr 10, 2014 by Anthony Devoz

1 Answer

0

I just figured it out my shifts were not correct should be 8 bits instead of 6. Also thanks to @Michael for giving the same answer.

answered on Stack Overflow Apr 10, 2014 by Anthony Devoz

User contributions licensed under CC BY-SA 3.0