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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:55:02+00:00 2026-05-27T08:55:02+00:00

Writing a compiler in school, last milestone is generating assembly code. Trying to learn

  • 0

Writing a compiler in school, last milestone is generating assembly code. Trying to learn NASM. Starting at the beginning, http://www.cs.lmu.edu/~ray/notes/nasmexamples/, trying to compile a Hello World.

; ----------------------------------------------------------------------------
; helloworld.asm
;
; This is a Win32 console program that writes "Hello, World" on one line and
; then exits.  It needs to be linked with a C library.
; ----------------------------------------------------------------------------

    global  _main
    extern  _printf

    section .text
_main:
    push    message
    call    _printf
    add     esp, 4
    ret
message:
    db      'Hello, World', 10, 0

To assemble, link and run this program under Windows:

nasm -fwin32 helloworld.asm
gcc helloworld.obj
a

Under Linux, you’ll need to remove the leading underscores from function names, and execute

nasm -felf helloworld.asm
gcc helloworld.o
./a.out

But I’m on OSX. Found this little resource: http://salahuddin66.blogspot.com/2009/08/nasm-in-mac-os-x.html. In Mac OS X we should use format macho…

nasm -f macho -o hello.o hello.asm

…and for the linker (we need to specify the entry point)…

ld -e main -o hello hello.o

But when I do this…

Undefined symbols:
    "printf", referenced from:
        _main in hello.o
ld: symbol(s) not found for inferred architecture i386

Sorry, I know it’s a lot to read. And I doubt there are many NASM coders around these parts, but worth a try right? I’d appreciate any help I can get.

  • 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-27T08:55:02+00:00Added an answer on May 27, 2026 at 8:55 am

    Function printf is defined in some C library (on Linux, that would be in e.g. /lib/libc.so.6 or /lib/x86_64-linux-gnu/libc.so.6) so you need to link to that library (I don’t know what it is on MacOSX)

    You could do directly system calls i.e. syscalls (I don’t know the details for MacOSX, and I don’t know if they are publicly available). On Linux, the Linux Assembly Howto give the details. You need to find equivalent details for your operating system.

    (BTW, using entirely free software is definitely easier for such tasks, because their specification and source code is available; with proprietary software like probably MacOSX is, you need to get the from the software provider, sometimes it is very very expensive)

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

Sidebar

Related Questions

I'm writing a compiler project which will produce assembly code as the target language.
I'm writing a compiler which uses C as an intermediate code which is (Currently)
I am experimenting with writing a toy compiler in ocaml. Currently, I am trying
While writing some C code, I decided to compile it to assembly and read
I'm writing a compiler that generates Jasmin code and want to invoke a method
I'm in the process of writing a compiler that will be generating ELF executable
I'm writing a compiler front end for a project and I'm trying to understand
In writing a compiler grammar, I'm trying to come up with a name/label for
I am currently writing a compiler which produces x86-32 code. However, I have a
Possible Duplicate: How to code a compiler in C? How would I start writing

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.