I have to write a short program in Assembly but my version not works. It should print ASCII char, next change it to the integer value by atoi function and print out this value. Important is using for that, procedures from C: puts() and atoi().
What I am doing wrong? Please explain it for me as clear as posible. I'm using gcc and I'm writing in intel_syntax Assembly.
It's my code:
.intel_syntax noprefix
.text
.globl main
main:
mov eax, offset msg
push eax
call puts
pop eax
push eax
call atoi
pop eax
push eax
call puts
pop eax
.data
msg:
.asciz "a"
Thank you in advance
Using
atoi
makes no sense in this context. Are you sure you are supposed to use that?Assuming you want to print the ascii code instead (which is
97
fora
) you could useprintf
or the non-standarditoa
instead.By the way, you are destroying the return value from
atoi
by thepop eax
. Also, you are missing theret
at the end ofmain
.Sample code using
printf
: