Author Topic: [solved] NASM - Help with tutorial for Hello World  (Read 10352 times)

Offline forevernoob

  • Jr. Member
  • *
  • Posts: 2
[solved] NASM - Help with tutorial for Hello World
« on: June 09, 2022, 09:46:51 PM »
Hi all,

Having issues following a NASM 64-bit "hello world" tutorial Beginning x64 Assembly Programming
I am not new to programming, but I am new to assembly (and I am open to any other 64 bit tutorials that may be a better fit or recommendation).

I have been able to compile to the executable but having issues actually printing "Hello, world" to the console output.
Can someone help me understand what is wrong?

I'm running Windows 10 and I'm using the following tooling.


Here's the process to build the executable. No errors are thrown on any of the steps.
Code: [Select]
nasm -f win64 -g hello_world.asm -l hello_world.lst
Code: [Select]
gcc -o hello_world hello_world.obj
Code within "hello_world.asm"
Code: [Select]
section .data
    msg db "Hello, world", 0
section .bss
section .text
    global main

main:
    mov rax, 1  ;   1 = write
    mov rdi, 1  ;   1 = to stdout
    mov rsi, msg;   string to display in rsi
    mov rdx, 12 ;   length of string, without 0
    syscall     ;   display the string
    mov rax, 60 ;   60 = exit
    mov rdi, 0  ;   0 = success exit code
    syscall     ;   quit
« Last Edit: June 10, 2022, 08:17:09 PM by forevernoob »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: NASM - Help with tutorial for Hello World
« Reply #1 on: June 09, 2022, 10:12:14 PM »
Hi forevernoob,

Welcome to the forum.

The problem is a simple one. The code you show is for Linux. I'm not good at 64 bit code and haven't run Windows since win 98 was current, so I can't help you much. The code you want for Windows will include things like:
Code: [Select]
extern getstdhandle
extern writefile
extern exitprocess
That doesn't include any code, but may help you identify code that will wprk fpr you. I don't know why this keeps happening, but you're not the first one tp have had this exact problem.

I may be able to find an example for Windows... although perhaps not a tutorial..

Best,
Frank

P.S. Well that was easy. Very next topic. Not exactly the code I had in mind, but it should get you started.

 Topic: NASM tutorial for Windows (7+), console and windows  (Read 19616 times)


« Last Edit: June 09, 2022, 10:20:57 PM by Frank Kotler »

Offline forevernoob

  • Jr. Member
  • *
  • Posts: 2
Re: NASM - Help with tutorial for Hello World
« Reply #2 on: June 09, 2022, 11:11:44 PM »
Well thank you Frank! This clears up a lot for me.

I thought the language being agnostic would mean I could print to console without the C externs.
I think it might be too much work to learn the language and translate OS differences at the same time.

I'll transition to a linux device to continue the tutorial for now.
Once I have a truly better understanding, I will try to transition back to Windows.

edit:
AND confirmed it works on Linux. You're amazing Frank, thank you truly!
« Last Edit: June 10, 2022, 08:16:50 PM by forevernoob »