Pelles C forum

Assembly language => Assembly discussions => Topic started by: PabloMack on May 09, 2019, 09:56:44 PM

Title: Assembler Doesn't Accept PUSH Immediate instruction
Post by: PabloMack 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
Title: Re: Assembler Doesn't Accept PUSH Immediate instruction
Post by: Vortex 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]
Title: Re: Assembler Doesn't Accept PUSH Immediate instruction
Post by: jj2007 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                               |
Title: Re: Assembler Doesn't Accept PUSH Immediate instruction
Post by: Vortex 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