Take the 2-minute tour ×

Just a short question. Anyone knows if there is any way that I can do this in assembly?

movl $4, %ebx
movl (%ebx)(%esp), %eax

what I'm trying to do is basically create a loop that extras the next argument(fixed size) from the stack.


int foo( int x, int y, int z, int a){
    if(x == y){
         x = z;
       if(y == z){
            printf("%d", a);

instead of immediately loading x, y, z and a into the register, can I load a into the register only when I'm sure that the first 2 conditions are true.

p/s: wrote the code on the fly, doesn't really do anything useful.

share|improve this question
What do you mean by (%ebx)(%esp)? –  m0skit0 Oct 5 '12 at 16:29
movl $4, %ebx does not look Intel to me. Looks AT&T. What's your compiler? –  Alexey Frunze Oct 5 '12 at 16:30
@m0skit0 Perhaps, ($esp,$ebx) or the other way around? –  Alexey Frunze Oct 5 '12 at 16:31
add comment

2 Answers

up vote 2 down vote accepted

You want this

movl $1, %ebx
movl (%esp,%ebx,$4), $eax

incrementing %ebx by one each time to get to the next argument.

share|improve this answer
add comment
movl (%esp,%ebx),%eax

is accepted by my compiler.

The syntax is

mov'suffix' (offset,base[,scale]),target

with the scale in brackets because it is optional

share|improve this answer
add comment

Your Answer


