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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:30:49+00:00 2026-06-11T12:30:49+00:00

I want to call at least 1 C function from assembly. It is because

  • 0

I want to call at least 1 C function from assembly. It is because I’m doing my own tiny OS from scratch(out of nothing). The reason i want to call c function from my boot loader. I can understand assembly but poor in writing my own program. So if i could transfer control from assembly procedure to c procedure my job is made easier.

So how to link assembly pgm and C program files into one. It is ok for me even if the file size exceeds 512 bytes.
I am doing this on Windows 7 with help of mingw. my c compiler is gcc and assembler is nasm.

  • 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-11T12:30:50+00:00Added an answer on June 11, 2026 at 12:30 pm

    easier to just show you an example, I found this on the internet a while ago and saved it as a source on my computer, not sure where from though

    ; printf1.asm   print an integer from storage and from a register
    ; Assemble: nasm -f elf -l printf.lst  printf1.asm
    ; Link:     gcc -o printf1  printf1.o
    ; Run:      printf1
    ; Output:   a=5, eax=7
    
    ; Equivalent C code
    ; /* printf1.c  print an int and an expression */
    ; #include 
    ; int main()
    ; {
    ;   int a=5;
    ;   printf("a=%d, eax=%d\n", a, a+2);
    ;   return 0;
    ; }
    
    ; Declare some external functions
    ;
            extern  printf      ; the C function, to be called
    
            SECTION .data       ; Data section, initialized variables
    
            a:  dd  5       ; int a=5;
    fmt:    db "a=%d, eax=%d", 10, 0 ; The printf format, "\n",'0'
    
    
            SECTION .text                   ; Code section.
    
            global main     ; the standard gcc entry point
    main:           ; the program label for the entry point
        push    ebp     ; set up stack frame
        mov     ebp,esp
        mov eax, [a]    ; put a from store into register
        add eax, 2      ; a+2
        push    eax     ; value of a+2
        push    dword [a]   ; value of variable a
        push    dword fmt   ; address of ctrl string
        call    printf      ; Call C function
        add     esp, 12     ; pop stack 3 push times 4 bytes
    
        mov     esp, ebp    ; takedown stack frame
        pop     ebp     ; same as "leave" op
    
    mov eax,0       ;  normal, no error, return value
    ret         ; return
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I want to call a function in javascript with arguments supplied from elsewhere
So, I want to call a Python callback function from C. At some point,
I want to call a method say success(message) of javascript from android activity. I
I want to call a function a number of times providing it with different
I want to call a function which is in another php class that I
I'm using a jQuery .each() call, which uses an anonymous function, from inside a
I want to call legacy c third party functions from python. I created a
I want to call a webservice using google closures, via jsonp since i am
I want to call a html page on click of a button in mvc.
i want to call the command prompt command using Process.Start and then using StandardOutput

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.