Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9182097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:28:48+00:00 2026-06-17T18:28:48+00:00

How do I pass parameters to a function in Assembly? I did push Last

  • 0

How do I pass parameters to a function in Assembly?
I did push Last Param, push Second Param, push First Param..

But I cannot access the parameters within Meh Function.. What I’m doing crashes the program..

format PE console                                ;Format PE OUT GUI 4.0
entry main

include 'macro/import32.inc'

section '.idata' import data readable           ;Import Section.
library msvcrt,'msvcrt.dll'
import msvcrt, printf, 'printf',\
exit,'exit', getchar, 'getchar'

section '.data' data readable writeable         ;Constants/Static Section.
InitialValue dd 0

section '.code' code readable executable
main:    
   push 67
   push 66
   push 65
   call MEH

   call [getchar]
   mov eax, 0
   ret 0

MEH:
   push ebx
   mov ebp, esp
   sub esp, 0

   mov eax, [ebp + 8]   ; Trying to print first parameter..
   push eax
   call [printf]
   add esp, eax

   mov esp, ebp
   pop ebx
ret
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:28:49+00:00Added an answer on June 17, 2026 at 6:28 pm

    Let’s see…

    Say your ESP is 0x00180078 on the outset, then after the three pushes you have

    00180078: 67
    00180074: 66
    00180070: 65
    

    then you call MEH, which immediately pushes ebx so now you have the stack as

    00180078: 67
    00180074: 66
    00180070: 65
    0018006C: return address
    00180068: ebx value
    

    you now load EBP with ESP = 00180068

    sub esp,0 does nothing
    
    mov eax, [ebp+8] ~ 00180068 + 8 = 00180070 = 65 
    

    so not the first but rather the last argument

       call [printf]
    

    Here comes your problem, though:

       add esp, eax
    

    What good was this supposed to do? Assuming printf preserves this argument passed in (which it is incidentally not required to do), why would you add the argument to the stack pointer? That is sure to mess up your return.
    What you want to do is restore esp to the value of ebp and pop back the saved ebx value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass 2 parameters with ajax function to the Controller Action, but
This is my code i want to pass parameters to the flyout function but
When you pass parameters to a function on the cpu stack, You put the
im trying to pass two parameters to a function, i being an int value
How can I pass parameters to the OnSuccess function of the AjaxOptions class in
Can I pass additional parameters to a predicate function? I need it in a
How do you pass all the parameters of one function into another function a(){
How to pass parameters to the function called by ElapsedEventHandler? My code: private static
I am trying to pass parameters to a function. I have: function test(var1, var2,
I'm trying to pass parameters to a function that is used in a RoutedEventHandler

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.