2

I'm new to assembly languages. I installed NASM and GoLink on Windows 10 and put their folder paths into Environment Variables in the advanced PC properties tab. I have a simple asm file with this program:

global _start

_start:
    mov eax, 1
    mov ebx, 42
    int 0x80

I run Command Prompt from the file folder and input following command:

nasm -f win32 test.asm -o test.obj

It successfully creates obj file in the same folder. Then I input this command:

golink /entry:_start /console kernel32.dll user32.dll test.obj

And I get the following error:

Error!
The following symbol was not defined in the object file or files:-
_start
You may be trying to link object files or lib code with decorated symbols -
If so, you could try using the /mix switch
Output file not made

I read that /entry appends a "_" to the name of the entry point but even with no underscore I get the same error.

How can I fix this?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
CrazyMan
  • 73
  • 7
  • Even if you do get that to link, the Windows kernel doesn't support `int 0x80` Linux system calls in native windows executable. This program can only work under Linux, e.g. in WSL2 or in a VM, or dual boot. – Peter Cordes Mar 18 '22 at 22:12
  • @PeterCordes, yes, I managed to link another program which included words ```section .data``` and ```section .text``` so I suspect that might've been the problem. With what can I replace ```int 0x80``` if I'm using Windows? – CrazyMan Mar 18 '22 at 22:27
  • @CrazyMan You have to call the appropriate function from `kernel32.dll`. Windows does not support doing system calls directly. While you technically can do so, the system calls change with every version of Windows and you should not do it that way. – fuz Mar 18 '22 at 22:33
  • [Hello world using nasm in windows assembly](https://stackoverflow.com/a/12575061) shows a working Windows program assembled with NASM and linked with GoLink. At the top of the .asm file, the current section is normally `.text`, i.e. there's an implicit `section .text` before the start of the file. At least I think so, so IDK why that would be a problem. You could start from the Hello World and remove parts of it until it's just a program that exits without printing. – Peter Cordes Mar 18 '22 at 22:42
  • 1
    @PeterCordes The implicit `section .text` doesn't work on Windows NASM for some reason I don't know. – xiver77 Mar 19 '22 at 02:08
  • @xiver77: oh, well that's probably the answer, then, explaining the link error if that's why GoLink doesn't find the symbol. (If it only looks in the .text section, or the symbol isn't in any section, missing from the object file). Interesting. – Peter Cordes Mar 19 '22 at 02:18

1 Answers1

2

As commentators mentioned, section .text is required when compiling in Windows 10. Also, I used int 0x80 which is system call used on Linux systems so the program wouldn't work anyway.

CrazyMan
  • 73
  • 7