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 7064215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:48:24+00:00 2026-05-28T04:48:24+00:00

Working on calling a C function from my asm project. I’m trying to push

  • 0

Working on calling a C function from my asm project.

I’m trying to push the integer value into the c function.

My code

mov rdi, [input]
push rdi                  ;push rdi into stack for c function to work with
call dtoch
pop  rdi                  ;to keep stack balanced 

‘
am I moving the input into the wrong register ?

Running on linux Ubuntu OS, not getting an error, it’s just not printing out the correct value.

When I run the function in a C environement it works fine, but with my nasm project it prints out wrong numbers….?

c function:

void dtoch(int d )
{
int n , r[10], i = 0, number, j = 0;
while (number > 0)
{
r[i] = number%16;
number = number/16;
i++;
j++;
}
printf ("It's hexadecimal equivalent is: ");
for (i = j -1; i > = 0; i--)
{
if (r[i] == 10)
printf("A");
else if (r[i] == 11)
printf("B");
else if (r[i] == 12)
printf("C");
else if (r[i] == 13)
printf("D");
else if (r[i] == 14)
printf("E");
else if (r[i] == 15)
printf("F");
else
printf("%d", r[i]);
}

}
  • 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-28T04:48:25+00:00Added an answer on May 28, 2026 at 4:48 am

    x64 uses __fastcall only, for Linux, the AMD64 ABI is used, see Agner fog’s optimization manuals for the differences or this nice summery table on wikipedia (on windows, see this (Microsoft ABI)).

    For your example running under Linux , you want it in RDI, no PUSHs(and the paired POP‘s) are needed. You can review the full AMD64 ABI here, it includes a few coding smaples (on windows you’d want your single arg to go into RCX, again, no PUSH‘s needed.).

    A a simple tip: you can compile your c calls with assembly output and see what code the compiler generates, the options -Wa,-adhln -g on GCC should do the trick.

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

Sidebar

Related Questions

I am working on an report for which am calling a function from front
Still working on a problem that started from here Calling C++ dll function from
I'm working from a question I posted earlier ( here ), and trying to
calling a js function using onclick... onclick=SubmitAge(66, 'ctl00_MainContent_arTo_upAgeRange') function just calls an updatePanel from
Is there a way to stop a function from calling print ? I am
I call C++ function from C# project: [System.Runtime.InteropServices.DllImport(C.dll)] public static extern int FillSlist(out string
I am calling a function twice from two different functions, But for one of
I've been working with Vector2's and XNA, and I've come to find that calling
I'm working on an audio-intensive app for the iPhone. I'm currently calling a number
I really want to know your experience at working with ADO.Net datasets (calling stored

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.