NASM Forum > Programming with NASM

Stack definition problem NASM-32bit-Linux

(1/2) > >>

tarek89:
Hello

I am writing intelx8086 32bit assembly programs on linux 64bit machine
the problem is i cant deal with stack

i used the declaration in NASM manual:

segment stack stack
 resb 64
stacktop:

it results with an error:
warning: Unknown section attribute 'stack' ignored on declaration of section `stack'
warning: uninitialized space declared in non-BSS section `stack': zeroing

i dont know what to do, i need to use the stack
here is a code for my stack checking program

--- Code: ---

section .data ;--------------Data Declaration-------------------

I_MSG DB 'Please Enter Number=',10 ;Input Msg for user
I_MSG_COUNT EQU $ - I_MSG ;Length of first message

segment stack stack
resb 64
stacktop:

section .text  ;---------------Code----------------------------

global _start

_start:

LEA ECX,[I_MSG] ;Moves offset of msg to EDX Register
MOV EDX,I_MSG_COUNT ;load the length of the stream to print
CALL _print
CALL _exit
;--------------------------Procedure _print-----------------
_print:
PUSHF
MOV EAX,4 ;sys_write
MOV EBX,1 ;file descriptor 1
INT 80h
RET
; Call Kernel
; Return

;---------------------------Procedure _exit-------------------
_exit: MOV EAX,1 ;sys_exit
MOV EBX,0 ;exit with no error
INT 80h
RET ;Call The Kernel
;Return





--- End code ---


IF i removed PUSHF it works fine with no error

Assemble: nasm -f elf prog.asm
Link: ld -m elf_i386 -s -o prog prog.o


Thank you in advance

Rob Neff:

--- Quote from: tarek89 on April 25, 2011, 09:09:35 PM ---
--- Code: ---;--------------------------Procedure _print-----------------
_print:
PUSHF          ;<-- THIS OPERATION IS...
MOV EAX,4
MOV EBX,1
INT 80h
RET             ;<-- MESSING UP YOUR CALL STACK

--- End code ---

--- End quote ---

Examine my comments within your source; Hopefully this will shed some light on why your stack gets hosed thus crashing your program...

tarek89:
Thank you alot i got it
but the reason is my main problem has a segmentation fault error which i dont know how to fix or even get where it is
so i made this small prog to test the push and pop issue

so how could i work on stack without even declaring it or reserving a size?

Rob Neff:

An extremely simple, contrived, and naive example:


--- Code: ---   sub  esp, 8  ;<-- make room on stack for 2 dwords
   mov  dword [esp], 42
   mov  dword [esp+4], ecx
   mov  eax, dword [esp]

--- End code ---

I am assuming of course that you are running on a 32-bit protected mode operating system...

tarek89:
ah i got it

so i dont have to declare a size or somthing, i mean i dont have to say something like .STACK 64 (MASM) instead i should SUB ESP,64 ??

Navigation

[0] Message Index

[#] Next page

Go to full version