Link to home
Start Free TrialLog in
Avatar of Enrique Mesa
Enrique Mesa

asked on

How to set up a stack frame properly? My function crashes when i set up a stack frame. x86 Assembly.

Hello. I am building an assembly program. I have no skills yet in this field. I am mainly a C++ programmer.

I am studying stack frames. I am set up a frame for a particular function, and it works. But when i call another function, it crashes.

I don't know how to set up it properly. I am tried setting up a stack frame from start but i dont' appears to do nothing. It crashes too.

Here is my original code. I don't know how to set up properly the stack frame.
;Copyright(c) Jorge Enrique Mesa Mosquera
;All rights reserved.

;GOALS:
;-Write a function and call it properly from the main body.
include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here

;Print a string
;Ask for username
;Print a string
;Ask for password
;Look up in table for right matching credentials
;If the credentials exists, then create a file with the credentials.
;

;Print a message asking for username
;Ask for a username string
;Save username string in a string variable

;Print a message asking for password
;Ask for a password string
;Save password string in a string variable.

;Check if the


.code

main:


        call function_enrique

        call function_enrique2
        invoke  ExitProcess,0

;Enrique is a function that receives four parameters, and show a message box using Win API
function_enrique:
        push ebp
        mov ebp, esp
        sub esp, 16
        ;push edi     ; Save the values of registers that the function
  ;push esi     ; will modify. This function uses EDI and ESI.

        invoke  MessageBox,HWND_DESKTOP,"Hi! From Enrique!","Enrique function is working fine!!",MB_OK

        ;pop esi
        ;pop edi

        ;Note: The compiler TCC produces a leave instruction replacing the epilogue. I can use it too,
        ;but i prefer to doing it manually as a way to learn more about how to deal with calling conventions.
        add esp, 16
        mov esp, ebp
        pop ebp
        ;leave
        ret
function_enrique2:
        invoke  MessageBox,HWND_DESKTOP,"Other","Another function!!",MB_OK
        ret
.end main

Open in new window

Please, a help facing this problem.

New: I have set up a stack frame but i don't know if it is right. The enter instruction is not avalaible for my FASM tool. I don't know why, i just want to set up stack frame properly.

Thanks.

I attached my source code. It is easy to read, it is just a single file with less than 30 lines.

It is intented to be compiled by FASM toolchain.

I also want a bit of insight about calling conventions. I am studying this sort of things before to move to something more complex.

Thanks buddies.
Avatar of tuvi
tuvi
Flag of United States of America image

I see no attachment
Avatar of Enrique Mesa
Enrique Mesa

ASKER

@tuvi I uploaded my soruce code. I am having some mistakes understanding the interface of website. XD. Nice day.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.