linux-assembly.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* suffix or operands invalid for
@ 2006-12-22  2:39 Kenton Brede
  2006-12-22 12:51 ` Frank Kotler
  0 siblings, 1 reply; 8+ messages in thread
From: Kenton Brede @ 2006-12-22  2:39 UTC (permalink / raw)
  To: linux-assembly

I've done some scripting but don't consider myself a programmer.  I
ran across "Programming from the Ground Up" and thought it would be an
interesting project.  At any rate I'm having problems compiling a
program I've copied out of the book.  I'm hoping someone can help me
out.  Thanks for any help.
Kent

Here are the errors when I run "as power.s -o power.o":

power.s: Assembler messages:
power.s:14: Error: suffix or operands invalid for `push'
power.s:15: Error: suffix or operands invalid for `push'
power.s:19: Error: suffix or operands invalid for `push'
power.s:22: Error: suffix or operands invalid for `push'
power.s:23: Error: suffix or operands invalid for `push'
power.s:27: Error: suffix or operands invalid for `pop'
power.s:61: Error: suffix or operands invalid for `push'
power.s:85: Error: suffix or operands invalid for `pop'

The code:

------------------------------------------------------------------------------------------------------------
.section .data

.section .text

.globl _start
_start:
pushl $3        #push second argument
pushl $2        #push first argument
call power      #call the function
addl $8, %esp   #move the stack pointer back

pushl %eax      #save the first answer before
                #calling the next function

pushl $2        #push second argument
pushl $5        #push first argument
call power      #call the function
addl $8, %esp   #move the stack pointer back

popl %ebx       #The second answer is already
                #in %eax. We saved the
                #first answer onto the stack,
                #so now we can just pop it
                #out into %ebx
addl %eax, %ebx #add them together
                #the result is in %ebx

movl $1, %eax   #exit (%ebx is returned)
int $0x80
.type power, @function
power:
pushl %ebp              #save old base pointer
movl %esp, %ebp         #make stack pointer the base pointer
subl $4, %esp           #get room for our local storage

movl 8(%ebp), %ebx      #put first argument in %eax
movl 12(%ebp), %ecx     #put second argument in %ecx

movl %ebx, -4(%ebp)     #store current result

power_loop_start:
cmpl $1, %ecx           #if the power is 1, we are done
je end_power
movl -4(%ebp), %eax     #move the current result into %eax

imull %ebx, %eax        #multiply the current result by
                        #the base number
movl %eax, -4(%ebp)     #store the current result

decl %ecx               #decrease the power
jmp power_loop_start    #run for the next power

end_power:
movl -4(%ebp), %eax     #return value goes in %eax
movl %ebp, %esp         #restore the stack pointer
popl %ebp               #restore the base pointer
ret
----------------------------------------------------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-12-31 18:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-22  2:39 suffix or operands invalid for Kenton Brede
2006-12-22 12:51 ` Frank Kotler
2006-12-22 14:18   ` Kenton Brede
2006-12-22 16:16     ` Robert Plantz
2006-12-22 16:55       ` Robert Plantz
2006-12-22 19:05         ` Kenton Brede
2006-12-22 19:15           ` Robert Plantz
2006-12-31 18:06     ` Hendrik Visage

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).