0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.