Hi, I'm using the GAS assembler on Linux (x86) and for some strange reason I can't get a pointer to a number to print out right when I pass it to a function, but if I push & pop it in the main function it prints the right value. What am I doing wrong?
Instead of printing out "Val - 105" it prints something like "Val - 11305948" and then gets a Segmentation Fault.
Code:
# - bubble.asm - Bubble sort...
.section .data
output:
.asciz "Values: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n"
endline:
.asciz "XXXXX\n"
val:
.asciz "Val - %d\n"
values:
.int 105, 235, 61, 315, 134, 221, 53, 145, 117, 5
.section .text
.globl main
main:
nop
movl $values, %esi
pushl %esi
call print
addl $4, %esp # Pop the stack.
push $0
call exit # exit( 0 );
# Function: void print( int* )
print:
popl %esi
pushl (%esi) # Push the value at address in esi on the stack.
pushl $val
call printf # printf( val, *esi );
addl $8, %esp # Pop the stack.
ret