# copyright -- Ivan Novick -- Feb-2008 -- ivan at 0x4849 dot net # x86 assembly -- print out an array of 10 long values # # as -o array.o array.s # ld -dynamic-linker /lib/ld-linux.so.2 -o array -lc array.o .section .data array: .long 10,20,30,40,50,60,70,80,90,100 # array of 10 longs arraysize: .long 10 fmtstring: .asciz "%d\n" # null terminated string .section .text .globl _start _start: movl $0, %eax # initialize the counter %eax loopbegin: # mark the beginning of the loop movl array(, %eax, 4), %ebx # move the array item into %ebx ##### CALL PRINTF ############################################################# pushl %eax # save the state of %eax pushl %ebx # 2nd parameter to printf call pushl $fmtstring # first parameter to printf call call printf # call libc addl $8, %esp # remove and discard %ebx and $fmtstring from stack popl %eax # restore the state of %eax counter ################################################################################ inc %eax # increment the counter cmp arraysize, %eax # compare the counter with the array size jl loopbegin # if the counter is less than the array size than do another iteration of theloop movl $1, %eax # code for the exit system call movl $0, %ebx # parameter to exit system call int $0x80 # system call