0

I'm trying to write a loop that will ask for user input for four numbers. The program compiles normally, the numbers are entered, but in the debugger using gdb-peda it is shown that with each integration, the last number input by the user is entered in place of all the numbers.

section .data
msg_x db 'Enter coordinate:', 0xa
len_x equ $ - msg_x

section .bss
x resb 2

section .text
global _start

_start:

enter:
mov eax, 4
mov ebx, 1
mov ecx, msg_x
mov edx, len_x
int 80h

mov eax, 3
mov ebx, 0
mov ecx, x
mov edx, 2
int 80h

push x
inc edi
cmp edi, 4
jb enter
felix
  • 1
  • 1
    You're pushing the address of `x`, not the value stored there. See https://stackoverflow.com/questions/10362511/basic-use-of-immediates-vs-square-brackets-in-yasm-nasm-x86-assembly – Michael Sep 22 '21 at 06:15
  • Think about the C equivalent: you're making a `char *array[]` on the stack where every entry points to the same static buffer you're reading into. – Peter Cordes Sep 22 '21 at 08:23

0 Answers0