Simple Hello world using x86 (32bit) assembly language using function

here is some hello world function that would just add 10 to whatever number it is given

#Simple adder function in assebmly - just adds 10 the called number 
.code32 #if running the code on 64 bit machine
.section .data
.section .text

.globl _start
_start: #entry point

    #Assign the number to be modified here
    push $9 # using immediate access mode just assign number 9
    call adder10 #call the function adder10 here - basically assign a memory address name

    mov %eax, %ebx #pass the return value to ebx since return value sits on eax
    mov $1, %eax  # call system call exit on register eax
    int $0x80 #yup - interrupt it!

.type adder10, @function # like declare a function here ;)
    #save the current base pointer first
    push %ebp

    #load the current stack pointer to the base pointer and use the new base pointer in the function
    mov %esp, %ebp

    #load the paramter on register ecx
    mov 8(%ebp), %ecx #access it using base index access method
    add $10, %ecx #do the magic

    #the return value will be on %eax
    mov %ecx, %eax

    #return the original values to the ebp and esp
    mov %ebp, %esp
    pop %ebp

Save the above file as adder.s
to run this if you are on 64 bit machine use

gcc -m32 -nostartfiles -o adder adder.s


as -o adder.o adder.s
ld -o adder adder.o

and run it as


to see the result

echo $?

If all ok the above should print 19