I keep seeing other examples ( not NASM ) saying that pushing an extra long is needed.
But I don't see that here or any other examples I see.
What's up with this?
section .note.openbsd.ident
align 2
dd 8
dd 4
dd 1
db 'OpenBSD',0
dd 0
align 2
section .text
global _start ;must be declared for linker (ld)
_syscall:
int 0x80 ;system call
ret
_start: ;tell linker entry point
push dword len ;message length
push dword msg ;message to write
push dword 1 ;file descriptor (stdout)
mov eax,0x4 ;system call number (sys_write)
call _syscall ;call kernel
;the alternate way to call kernel:
;push eax
;call 7:0
add esp,12 ;clean stack (3 arguments * 4)
push dword 0 ;exit code
mov eax,0x1 ;system call number (sys_exit)
call _syscall ;call kernel
;we do not return from sys_exit,
;there's no need to clean stack
section .data
msg db "Hello, world!",0xa ;our dear string
len equ $ - msg ;length of our dear string
This needs an extra long (of any value) pushed.
entropy@theo {~/asm} cat hello.s
.section ".note.openbsd.ident", "a"
.p2align 2
.long 0x8
.long 0x4
.long 0x1
.ascii "OpenBSD\0"
.long 0x
.p2align 2
.section .data
hello:
.ascii "Hello, World!\n\0"
.section .text
.globl _start
_start:
pushl $14 # number of bytes to write
pushl $hello # address of our string
pushl $1 # 1 is stdout
pushl %eax # push the extra long
movl $4, %eax # 4 is write syscall
int $0x80 # call the kernel
addl $12, %esp # clean the stack - add ((# of pushl's)-1)*4 to esp
xor %eax, %eax # set eax to 0
pushl %eax # pushl return (status value)
pushl %eax # pushl extra long
movl $1, %eax # 1 is exit syscall
int $0x80 # call the kernel
Assemble, link and execute.