-1

I have to iterate through the stack to temporary move the values of the words to a register, something like this:

movq    ((i - 3)*8)(%rsp), %esi

or

movq    %rcx, %rbx                # where %rcx is the counter
        subq    $3, %rbx         
        movq    $8, %rax
        mulq    %rbx
        movq    (%rbx)(%rsp), %esi

But obviously, neither of the above works, so how should I change it to make it work?

Ralph
  • 145
  • 1
  • 2
  • 8
  • why don't you do directly `mov esi,[rsp+rcx*8-24]`? (I couldn't bother with AT&T syntax, sorry). ... btw, it's not obvious why yours doesn't work. I would guess the compiler doesn't like the additional parentheses? Maybe `movq -24(%rsp,%rcx,8),%esi` is AT&T syntax? I don't want to mess with it, blargh. Read some docs, if you really want it. – Ped7g Oct 15 '16 at 19:07
  • @Ped7g your answer is the most direct interpretation of `movq ((i-3)*8)(%rsp),%esi`, except in both cases, a 64 bit value can't be moved to a 32 bit register, so it should be `movl`. Also, you comment should have been formulated as an answer, so readers looking at list of questions can see it was answered and ideally, OP marks as being the solution. – Shift_Left Oct 15 '16 at 19:31
  • @Ped7g In AT&T syntax that's `mov -24(%rsp,%rcx,8),%esi`. – fuz Oct 15 '16 at 23:43

1 Answers1

0

movl -24(%rsp,%rcx,8),%esi

Please, read the AT&T syntax documentation (and have it around).

Personal bias: while usually I don't mind alternatives, in case of x86 assembly I think the MASM quirk mode should be burnt, and AT&T should be used only by compilers as machine format for further compilation/etc, but not by humans. If you insist on using AT&T, go ahead, but I will consider you being a masochist.

Just to compare, Intel syntax (nasm):
mov esi,[rsp+rcx*8-24]

Ped7g
  • 16,236
  • 3
  • 26
  • 63
  • I indeed came across something like this in docs, but it was still pretty vague. Thanks for the answer! – Ralph Oct 16 '16 at 07:16