I'm trying to make a simple program: it allocates an integer in the stack, calls% c_of% of the C library, and prints it to the screen. I have already disassembled it in C , and I try to reimplement it, without success. I tested the allocation without making any C call without any error. The problem is the Microsoft x64 convention. What is wrong with the following program?
bits 64 section .data local1 db 'Hello. Input a number, please.',10,'> ', 0 local2 db '%u', 0 local3 db 10,'You input: %u', 0 section .text extern printf extern scanf extern exit extern getch global WinMain WinMain: push rbp mov rbp, rsp mov dword[rbp - 4], 0 ; = push dword 0 em 64 bits mov rcx, local1 call printf ;imprime o "pedido" mov rcx, local2 lea rdx, [rbp - 4] ;endereço da variável alocada call scanf mov rcx, local3 call printf call getch xor rcx, rcx ;coloca o valor de saída como 0 call exit ;sai mov rsp, rbp pop rbp ;stack frame de saída leave
PS: (Consider | a line break) I have already tried to change
mov dword[rbp - 4], 0 and
sub rsp, 4 | mov dword[rsp-4], 0 (
push word 0 | push word 0 is illegal in 64 bits).