I'm struggling to convert a given integer into hex. I'm not getting correct output and it's likely due to incorrect shifting of bits. The algorithm I tried was to start at the 3rd position The code:
.globl hex_str
hex_str:
movl $48, 0(%rsi)
movl $120, 1(%rsi)
movl $0, 10(%rsi)
mov $0xf, %r10d
mov $1, %r8d
mov $2, %r9d
mov $0, %ecx
loop:
inc %r8d
and %r10d, %edi
movl %edi, %r11d
shr $4, %r11d
movl %r11d, 2(%rsi)
inc %r9
cmp $9, %r8d
jg endl
jmp loop
endl:
ret
Output received:
1 = 0x
34 = 0x
819 = 0x
17476 = 0x
349525 = 0x
6710886 = 0x
125269879 = 0x
19088743 = 0x
2309737967 = 0x
3735928559 = 0x
3235822174 = 0x
The correct output should contain '0x' followed by 0's and the correct hex.