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

  • Home
  • SEARCH
  • 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 3439352
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:17:58+00:00 2026-05-18T08:17:58+00:00

How could one write a function, in assembly, that just forwards it’s arguments to

  • 0

How could one write a function, in assembly, that just forwards it’s arguments to another function and adds a couple extra?

So far, I pushed on the two extra arguments, then just jmped to the other function. Is that valid? Assuming that I make it a naked function, no prolog/epilog. I’m in x86.

  • 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-05-18T08:17:59+00:00Added an answer on May 18, 2026 at 8:17 am

    If you want to do this, you need to pop the return address, push your two arguments, push the return address back onto the stack, and then do the jump.

    The discussion below assumes that you’re doing this in an environment that doesn’t reserve the registers I tinker with, and you’re using a pure stack-based calling convention. If there are reserved registers (for example, if you’re writing an ASM function to be called by a C program) or the calling convention is register-based, then things would have to be somewhat different.

    Also, be sure to read the disclaimer at the end.

    With that out of the way …

    Imagine you have a function that’s called with two parameters on the stack. The stack frame, on entry to your function, would look like this:

    arg1
    arg2
    return addr
    

    Let’s not quibble about argument ordering (i.e. cdecl vs stdcall).

    Now, you want to pass control to another function that expects those two arguments and two more. On entry to that function, the stack frame should look like this:

    arg1
    arg2
    arg3
    arg4
    return addr
    

    So your first function has to pop the return address, add the two new parameters, push the return address, and do the jump:

    passthrough:
        ; save the return address
        pop ax
        ; Do stuff here to load values in BX and CX
        ; now push BX and CX (other parameters)
        push bx
        push cx
        ; restore the return address
        push ax
        ; Branch to the new function.
        ; The new function's RETurn will return to the caller of this function
        jmp new_function
    

    (Yes, I did that with 16-bit instructions. Just change ax to eax, etc.)

    Also, and this is very important: this only works if the callee is expected to clean up the stack. If the caller is expected to clean up the stack (typically by poping or by adding to the stack pointer), then this technique will fail because the caller will be expecting to remove 2 parameters from the stack when there are actually 4. The result will be a corrupted stack frame and when the caller tries to do a ret instruction, it’s going to wander off into the weeds.

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

Sidebar

Related Questions

Could one write a function that returns the number of elements in an enum?
How could one write the identity function in clojure using anonymous function literal (#())
I want to write a function that could check every item in a list
Could you say me, how to write a function, which takes as its (one
From time to time I write a function that just creates something if it's
I'm trying to write a function that takes two string arguments and returns the
One solution that one could suggest is to periodically look for a special 'Screen-saver'
One of the arguments I've heard against functional languages is that single assignment coding
How could one approximate Inverse Incomplete gamma function Г(s,x) by some simple analytical function
I need to write a function that takes 4 bytes as input, performs a

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.