Reputation: 2540
I am trying to print the first value in the array I declared:
global _main
extern _printf
section .data
array db "1","2","3","4","5","6","7","8","9"
fmt db "%d",0
section .text
_main:
push ebp
mov ebp, esp
mov ebx, array
mov eax, [ebx]
push eax
push fmt
call _printf
add esp, 4
pop eax
mov esp, ebp
pop ebp
ret
However, the output isn't 1
, it's some really large number. I thought by putting quotes around each integer, I would be printing the symbol, not the equivalent ASCII.
Upvotes: 0
Views: 91
Reputation:
You use db
, which means define byte, single character while you seem to expect an integer in the format, %d
.
You should use dd
instead and remove the quotes:
array dd 1, 2, 3, 4, 5, 6, 7, 8, 9
fmt db "%d", 0
or use %c
if you want to print a char:
array dd "1","2","3","4","5","6","7","8","9"
fmt db "%c", 0
plus, here:
add esp, 4
should be:
add esp, 8
you pushed two arguments.
Upvotes: 1