I need simply to grab the first character from a string and keep its decimal value (according to ASCII: if I grab 'h'
- I want to keep 104
).
I was trying to find this and tried everything - nothing works for me.
I'm getting my pointer to the first char in string in rdi
. Result in rax
.
I tried this
movb (%rdi), %al
ret
al
- byte version of rax
. As I know, 8 bits are used to store char
.
If in my main.c
I first put result in the character and then output as a decimal it perfectly works.
But if I right away output result of assembly code as an integer it gives me garbage.
If I check this assembly code with gdb
, using i r al
before the output to see the value of al
it gives me right answer.
More than that, if I run program multiple times, it always give me different 'garbage'.
How to fix it?
Thank you.