Sorry for the delay .
I was a bit busy collecting appropriate examples for my level .
I found three for my needs .
Linux ASM example
section .text
global _start ;must be declared for linker (gcc)
_start: ;tell linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov edx,9 ;message length
mov ecx,s2 ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Displaying 9 stars',0xa ;a message
len equ $ - msg ;length of message
s2 times 9 db '*'
Hello world windows
%include "io.inc"
section .data
msg db 'Hello, world!', 0
section .text
global CMAIN
CMAIN:
mov ebp, esp
PRINT_STRING msg
NEWLINE
xor eax, eax
ret
Hello world 2 ; windows
%include "io.inc"
section .text
global CMAIN
CMAIN:
mov ebp, esp; for correct debugging
; ----------------------------------------------------------------------------
; hello.asm
;
; This is a Win32 console program that writes "Hello, World" on one line and
; then exits. It uses only plain Win32 system calls from kernel32.dll, so it
; is very instructive to study since it does not make use of a C library.
; Because system calls from kernel32.dll are used, you need to link with
; an import library. You also have to specify the starting address yourself.
;
; Assembler: NASM
; OS: Any Win32-based OS
; Other libraries: Use gcc's import library libkernel32.a
; Assemble with "nasm -fwin32 hello.asm"
; Link with "ld -e go hello.obj -lkernel32"
; ----------------------------------------------------------------------------
global go
extern _ExitProcess@4
extern _GetStdHandle@4
extern _WriteConsoleA@20
extern _ReadConsoleA@20
section .data
msg: db 'Hello, World', 10
handle: dd 0
read_handle dd 0
written: db 0
section .text
go:
; handle = GetStdHandle(-11)
push dword -11
call _GetStdHandle@4
mov [handle], eax
push -10 ; stdin
call _GetStdHandle@4
mov [read_handle], eax
; WriteConsole(handle, &msg[0], 13, &written, 0)
push dword 0
push written
push dword 13
push msg
push dword [handle]
call _WriteConsoleA@20
push eax
mov eax, esp ; buffer for char?
push 0
push written ; reuse this?
push 1 ; characters to read?
push eax
push dword [read_handle]
call _ReadConsoleA@20
pop eax ; character read in al?
; ExitProcess(0)
push dword 0
call _ExitProcess@4
xor eax, eax
ret
Reading a couple of books too :-)