Hey, i am learning from Programming from the ground up. I am having a bit of trouble with the pushl and popl commands. I'm a newbie with ASM and really just starting out on it, i am on a x86-64 im presuming it will run the x86 32bit code. I ran other example code which didn't use push or pop, and it ran fine; it only really moved values around in the registers.
The error im getting on ALL my push and pop commands:
Error: suffix or operands invalid for `push'
Error: suffix or operands invalid for `pop'
Here is the source code which im using, i've tested it on other people's snippets as well but with the same result. So i don't think its the source code.
#PURPOSE: Program to illustrate how functions work
# This program will compute the value of
# 2^3 + 5^2
#
#Everything in the main program is stored in registers,
#so the data section doesn’t have anything.
.section .data
.section .text
.globl _start
_start:
pushl $3
pushl $2
call power
addl $8,%esp
pushl %eax
pushl $2
pushl $5
call power
addl $8,%esp
popl %ebx
addl %eax, %ebx
movl $1, %eax
int $0x80
#PURPOSE: This function is used to compute
# the value of a number raised to
# a power.
#
#INPUT: First argument - the base number
# Second argument - the power to
# raise it to
#
#OUTPUT: Will give the result as a return value
#
#NOTES: The power must be 1 or greater
#
#VARIABLES:
# %ebx - holds the base number
# %ecx - holds the power
#
# -4(%ebp) - holds the current result
#
# %eax is used for temporary storage
#
.type power, @function
power:
pushl %ebp
movl %esp,ebp
subl $4,%esp
movl 8(%ebp), %ebx
movl 12(%ebp),%ecx
movl %ebx, -4(%ebp)
power_loop_start:
cmpl $1,ecx
je end_power
movl -4(%ebp),%eax
imull %ebx,%eax
movl %eax,-4(%ebp)
decl %ecx
jmp power_loop_start
end_power:
movl -4(%ebp),%eax
movl %ebp,%esp
popl %ebp
ret