NO

Author Topic: Assembler Doesn't Accept PUSH Immediate instruction  (Read 946 times)

Offline PabloMack

  • Member
  • *
  • Posts: 8
Assembler Doesn't Accept PUSH Immediate instruction
« on: May 09, 2019, 09:56:44 pm »
I just tried to assemble a push immediate instruction and the
assembler doesn't like it. The AMD64 Ref Manual Vol 3 says
that it should take a number, sign extend it and push the
resulting 64-bit number onto the stack. The immediate can be
either a 1-byte (Opcode 6A) or 4-byte (Opcode 68) value.

The error is: "Invalid combination of opcode and operands (or wrong CPU setting)"

;Empty Main Program

          .code
;********** Empty Main Program **********
main        proc

            push 28h

main        endp

            end

Offline Vortex

  • Member
  • *
  • Posts: 518
    • http://www.vortex.masmcode.com
Re: Assembler Doesn't Accept PUSH Immediate instruction
« Reply #1 on: May 11, 2019, 01:03:26 pm »
In 64-bit assembly programming, you cannot push immediate values to the stack :

Code: [Select]
    hwnd=CreateWindowEx(
        WS_EX_CLIENTEDGE,
        szClassName,
        "Simple window",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 480, 400,
        NULL, NULL, hInstance, NULL);

assembled as :

Code: [Select]
xor     eax, eax
mov     qword ptr [rsp+58H], rax
mov     qword ptr [rsp+50H], rbx
xor     eax, eax
mov     qword ptr [rsp+48H], rax
xor     eax, eax
mov     qword ptr [rsp+40H], rax
mov     eax, 400
mov     dword ptr [rsp+38H], eax
mov     eax, 480       
mov     dword ptr [rsp+30H], eax
mov     eax, 2147483648
mov     dword ptr [rsp+28H], eax
mov     eax, 2147483648
mov     dword ptr [rsp+20H], eax       
mov     r9d, 13565952 
lea     r8, ptr [@337]
lea     rdx, ptr [szClassName] 
mov     ecx, 512
call    qword ptr [__imp_CreateWindowExA]
Code it... That's all...

Offline jj2007

  • Member
  • *
  • Posts: 508
Re: Assembler Doesn't Accept PUSH Immediate instruction
« Reply #2 on: May 11, 2019, 05:44:03 pm »
In 64-bit assembly programming, you cannot push immediate values to the stack :

Why not?
Code: [Select]
0000000140001229   | 68 78 56 34 12            | push 12345678                         |
000000014000122E   | 58                        | pop rax                               |
0000000140001229   | 6A 7B                     | push 7B                               |
000000014000122B   | 58                        | pop rax                               |

Offline Vortex

  • Member
  • *
  • Posts: 518
    • http://www.vortex.masmcode.com
Re: Assembler Doesn't Accept PUSH Immediate instruction
« Reply #3 on: May 12, 2019, 11:51:46 am »
OK, a correction here : Poasm does not accept this :

Code: [Select]
\PellesC\bin\poasm.exe /AAMD64 Test.asm
Test.asm(5): error: Invalid combination of opcode and operands (or wrong CPU setting).
Code: [Select]
.code

start:

   push 12345678

   ret

END
Code it... That's all...