0

So I have the following.

0000024E9689000A | 68 FF 7F 00 00           | push 7FFF                               |
0000024E9689000F | 68 45 B2 8C DF           | push FFFFFFFFDF8CB245                   |
0000024E96890014 | 58                       | pop rax                                 |
0000024E96890015 | 50                       | push rax                                |
0000024E96890016 | C3                       | ret                

I want to combine two DWORDs, first pushing high one, then low and popping into rax which if I understood correctly it should combine these 2 on stack into a QWORD.

The process is 64-bit, what am I doing wrong?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Leex Al
  • 9
  • 1
  • What does this have to do with C++? – Jonathan Mee Feb 10 '18 at 18:11
  • 2
    You can't `pushl` in 64bit. – llllllllll Feb 10 '18 at 18:11
  • You are showing some code but you haven't indicated what the specific result of that code is you are seeing, nor exactly the result you expect. So it's hard to answer the question "...what am I don't wrong?" – lurker Feb 10 '18 at 18:18
  • 2
    You can do this with a shl and an or. – Brandon Feb 10 '18 at 18:34
  • Is there an instruction that treats two 32-bit registers as one 64 bit register? – Thomas Matthews Feb 10 '18 at 18:40
  • 2
    In your example, the values are constants, so the obvious solution is to simply load the combined constant into rax. Please change your question to show what you *actually* want to do. – prl Feb 10 '18 at 18:50
  • @Thomas, yes, but not one that will help with this question. For example, div and wrmsr. – prl Feb 10 '18 at 18:53
  • you can also do `push ` `mov dword [rsp+4],` `ret` ... the first push will store 8 bytes (sign extended 32 bit immediate), the second `mov` will overwrite top 4 bytes of that, and `ret` will jump to the combined address (looks to me like you don't really need to set it up to `rax`, but if you do, you can still do ahead of `ret`: `mov rax,[rsp]`). Overall this is very likely some Problem XY, and you are probably forcing yourself into some weird solution... (also if this is about "retpoline" indicate that in Q). – Ped7g Feb 10 '18 at 19:04
  • related / possible duplicates: [Moving 64-bit constant to memory in x86 Assembly](https://stackoverflow.com/questions/46395630/moving-64-bit-constant-to-memory-in-x86-assembly) / [push on 64bit intel osx](https://stackoverflow.com/questions/13351363/push-on-64bit-intel-osx) / [How many bytes does the push instruction pushes onto the stack when I don't specify the operand size?](https://stackoverflow.com/questions/45127993/how-many-bytes-does-the-push-instruction-pushes-onto-the-stack-when-i-dont-spec) – Peter Cordes Feb 11 '18 at 02:34
  • Or for combining runtime-variable values: [Packing two DWORDs into a QWORD to save store bandwidth](https://stackoverflow.com/questions/47242353/packing-two-dwords-into-a-qword-to-save-store-bandwidth). – Peter Cordes Feb 11 '18 at 02:35

2 Answers2

1

you want this:

mov rax, upperHalf
mov rdx, lowerHalf
shl rax, 32
or rax, rdx?

?

sivizius
  • 450
  • 2
  • 14
  • 1
    If they're constants, `mov rax, imm64`. Otherwise if they're already zero-extended in separate register, then yes this works. Or see [Packing two DWORDs into a QWORD to save store bandwidth](https://stackoverflow.com/questions/47242353/packing-two-dwords-into-a-qword-to-save-store-bandwidth) – Peter Cordes Feb 11 '18 at 02:12
  • `mov` does not allow 64bit immediates, only 32bit immediates, that are sign-extended to 64bit. another way would be to store this immediate some where and load it via `mov rax, qword [ myImmediate ]` – sivizius Feb 11 '18 at 02:53
  • 1
    No, [REX.W=1 mov-to-register (opcode=B8+reg_number)](https://github.com/HJLebbink/asm-dude/wiki/MOV) does have 64-bit immediates, unlike `mov r/m64, sign_extended_imm32` or any other x86-64 instruction. AT&T syntax call this movabs. It's the REX.W=1 version of 5-byte `mov r32, imm32`. – Peter Cordes Feb 11 '18 at 02:56
0

For constants, use 10-byte mov r64, imm64 like a normal person. (Unlike any other instruction, there is a form of mov with a 64-bit immediate.)

mov rax, 0x7FFFDF8CB245 assembles just fine.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847