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 ;) adder10: #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 ret
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
otherwise
as -o adder.o adder.s ld -o adder adder.o
and run it as
./adder
to see the result
echo $?
If all ok the above should print 19
See how you would solve these known algorithm problems
find longest word in the sentenceFind the pairs that makes K Complementary in the given array java solution
Implementing tokenizer and adding tokens to the linked list
Get maximum occurring character
binary tree problems with solution
Find the first occurence of number in the sorted array
Flatten nested javascript array
Finding missing numbers from billion sequential number list file
Find longest palindrom from sequence of characters
Check if there are three numbers a, b, c giving a total T from array A