/* To build and run this: as fun_hello_world.s -o fun_hello_world.o --32 ld -m elf_i386 fun_hello_world.o ./a.out */ .section .data hwmessage: .asciz "Hello World\n" .section .text .globl _start _start: push $10 call printhw movl $27, %ebx movl $1, %eax int $0x80 /* Print "hello world" a given number of times We'll follow 32-bit C calling convention and put the paramter on the stack */ printhw: push %ebp mov %esp, %ebp // We'll have one local variable, and it'll be the loop counter sub $4, %esp movl 8(%ebp), %eax movl %eax, (%esp) // Loop for printing loop_top: movl (%esp), %eax cmpl $0, %eax je done dec %eax movl %eax, (%esp) movl $4, %eax movl $1, %ebx movl $hwmessage, %ecx movl $12, %edx int $0x80 jmp loop_top done: mov %ebp, %esp pop %ebp ret