The stack pointer is establish by the system when your program is called, but you need to set up ebp
the way you need it. It's not guaranteed to be equal to the stack pointer at the start, or some specific value relative to the stack pointer. For reference, see: x86 function stack frames.
In your case, it appears that you are assuming some parameters have been pushed on the stack, and you want to quit after you've exhausted these parameters. Either your code needs to know how many there are, or the first parameter needs to be a count of how many there are and you can use that count. In either case, you put the count into a count register (ecx
is convenient if you want to use the loop
instruction) and loop based upon the count. Also, from your code, I'm assuming that the parameters are addresses (pointers) to the data. For example:
SECTION .data
SECTION .bss
SECTION .text
global _start
_start:
mov ebp,esp ; point to the parameters via ebp
mov ecx,[ebp] ; first parameter is the count of values
; or, for example, "mov ecx,4" if there are fixed 4 params
mov esi,1 ; Initial index to parameters
_loop:
push ecx ; save the loop counter
; Uncomment these to save ebp and esi if int 80h uses these registers
;push ebp
;push esi
mov eax,4 ; sys_write call
mov ebx,1 ; stdout
mov ecx,[ebp+4*esi] ; get the next pointer
mov edx,4 ; print 4 characters
int 80h
; Uncomment these to restore esi and ebp if int 80h uses these registers
;pop esi
;push ebp
inc esi ; next parameter index
pop ecx ; restore the loop counter
loop _loop
mov eax,1
mov ebx,0
int 80h