Author Topic: How do I set the entry point? The official documentation's explanation is wrong.  (Read 17676 times)

Offline ben321

  • Full Member
  • **
  • Posts: 185
The documentation at http://www.nasm.us/doc/nasmdoc7.html says this about defining an entry point for win32 code
Quote
7.4.6 ..start: Defining the Program Entry Point

OMF linkers require exactly one of the object files being linked to define the program entry point, where execution will begin when the program is run. If the object file that defines the entry point is assembled using NASM, you specify the entry point by declaring the special symbol ..start at the point where you wish execution to begin.

So here's the EXACT code that's in my test.asm file. It is the ABSOLUTE SIMPLEST CODE POSSIBLE, and if I can't get it to work, I won't be able to get ANYTHING to work.

Code: [Select]
..start:
nop

And guess what.
When I run the compiler with this command (which is the correct command for compiling win32 assembly) it doesn't work!
Quote
nasm -f win32 test.asm

The error it returns is:
Quote
test.asm:1: error: unrecognized special symbol '..start'

So obviously the documentation for the NASM compiler, and the ACTUAL BEHAVIOR of the compiler, DO NOT MATCH, IN ANY WAY SHAPE OR FORM!

I don't know who's maintaining the documentation, and who's maintaining the compiler nasm.exe, but they must be 2 different people, who RARELY talk to each other, so neither of them is able to coordinate what they are doing with the other. This is an ABSOLUTE TRAVESTY! I can't even get my first assembly language program off the ground, because the documentation I'm DEPENDING ON to know how to use NASM is COMPLETELY USELESS documentation!

I hope an official developer for this project comes forward and tells me the REAL WAY to set an entry point, because the documentation sure is NOT HELPING.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Hi again ben123,

Unfortunately, the development team is currently unable to provide someone to read the documentation to you. Try it again yourself...

The section where you see "..start" applies to the "-f obj" output format - and only the "-f obj" output format. The "special symbol" "..start" is unique to this format, and will produce the error message you see if used in any other format. If you assemble with "-f obj" you will not get this error... but that's probably not what you want to do...

Most likely, you want to stick with "-f win32" as you've done. Read on to section 7.5 for that. Nasm doesn't know any "special" entrypoint in this format, so you will need to declare whatever symbol you use as "global" (Nasm knows that "..start" needs to be "global"... but only in "-f obj").
Code: [Select]
global myentrypoint
section .text ; (note that ".text" is case sensitive!)
; subroutines can go here, if you wish
myentrypoint:
; let the ceremony begin...
Linkers usually default to some known entrypoint - typically "start" or "_start" (or "winmain@16" ?). If you use something else, you will have to advise the linker of it - "/entry myentrypoint" or "-e myentrypoint" or some such. Check your linker's documentation.

So that's how you set an entrypoint - either use "..start" and "-f obj" (and an appropriate linker - I think most of 'em will still do OMF - Object Module Format - but may whine about doing the conversion), or, in other formats, declare a symbol "global". The command line to the linker will be simpler if you use a symbol the linker knows about - Nasm doesn't care.

Sorry you ran into this confusion. "The first days are the hardest days..." - Grateful Dead

Best,
Frank


Offline ben321

  • Full Member
  • **
  • Posts: 185
Hi again ben123,

Unfortunately, the development team is currently unable to provide someone to read the documentation to you. Try it again yourself...

The section where you see "..start" applies to the "-f obj" output format - and only the "-f obj" output format. The "special symbol" "..start" is unique to this format, and will produce the error message you see if used in any other format. If you assemble with "-f obj" you will not get this error... but that's probably not what you want to do...

Most likely, you want to stick with "-f win32" as you've done. Read on to section 7.5 for that. Nasm doesn't know any "special" entrypoint in this format, so you will need to declare whatever symbol you use as "global" (Nasm knows that "..start" needs to be "global"... but only in "-f obj").
Code: [Select]
global myentrypoint
section .text ; (note that ".text" is case sensitive!)
; subroutines can go here, if you wish
myentrypoint:
; let the ceremony begin...
Linkers usually default to some known entrypoint - typically "start" or "_start" (or "winmain@16" ?). If you use something else, you will have to advise the linker of it - "/entry myentrypoint" or "-e myentrypoint" or some such. Check your linker's documentation.

So that's how you set an entrypoint - either use "..start" and "-f obj" (and an appropriate linker - I think most of 'em will still do OMF - Object Module Format - but may whine about doing the conversion), or, in other formats, declare a symbol "global". The command line to the linker will be simpler if you use a symbol the linker knows about - Nasm doesn't care.

Sorry you ran into this confusion. "The first days are the hardest days..." - Grateful Dead

Best,
Frank


Sorry I missed that. I did a Google search for "NASM entry points" and the first search result that looked relevent was the one pointing to the page that contained the info about using ..start: as the way to set the entry point. So I assumed that this was THE ABSOLUTE CORRECT WAY to set an entry point when using NASM. When it didn't work, I assumed that either the documentation was wrong or NASM itself was really buggy.

Thanks for clearing that up. Though I did eventually find this was the, answer elsewhere than this forum, by doing many more Google searches for sample assembly code who's syntax was formatted to work in NASM.