flat assembler
Message board for the users of flat assembler.

Index > Linux > Trying to pass a structure to registry via stack; linux, x64

Author
Thread Post new topic Reply to topic
jorido



Joined: 23 Jan 2017
Posts: 53
jorido 13 Oct 2017, 05:04
There's a function which accepts a struct and its length as its arguments. I'm trying to pass a struct to it via registers, without using "struc", but manually:

Code:
  ;....................

  push 3; 3rd field of a struct
  push 2; 2nd field of a struct
  push 1; 1st field of a struct
  mov rdi, rsp; load a struct ---(dw, dw, dw) --- into rdi
  mov rsi, 6 ; its size dw + dw + dw = 6

  ;......................
  syscall
    


The app isn't working as expected. Is there a mistrake in the way of how I'm passing a struct via stack?
Post 13 Oct 2017, 05:04
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 799
Location: Russian Federation, Sochi
ProMiNick 13 Oct 2017, 13:23
In AMD64 mode there is no 16 bit push.

Why not just: mov rdi,1+2 shl 16 + 3 shl 32?
with pushes it will be:
push 3
push 1+2 shl 16
mov rdi,rsp
Post 13 Oct 2017, 13:23
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 13 Oct 2017, 14:01
ProMiNick wrote:
In AMD64 mode there is no 16 bit push.
The original AMD64 architecture had 16-bit PUSH in long mode (as a side effect of the prefix-opcode symmetries) and it was a documented behavior*. Later, when Intel adopted the same architecture, it removed these atypical encoding variants (I don't blame them).

You can still get fasm to generate the 16-bit variants in long mode with the PUSHW mnemonic. That said, I would not recommend even trying this route. Probably only the earliest CPUs implementing x86-64 architecture really supported this.

___
* I just opened the original x86-64 manuals to look for this just to make sure that I have no false memory of it. I'm attaching the excerpt I found - the PUSH instruction is listed earlier in the table, but the note below the table is what I wanted to show. This may be one of the first time I opened these paper manuals in ages, the last time I was really reading them was back in 2004 when working on x86-64 support for fasm.


Description:
Filesize: 58.12 KB
Viewed: 6653 Time(s)

amd64_16bit.jpg


Post 13 Oct 2017, 14:01
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.