Skip to content

Hibob555556/HelloAssembly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HelloAssembly

A small NASM assembly demo that includes both a Linux example with a C harness and a native Windows console example.

Files

  • hello.asm - a NASM x86-64 Linux assembly routine that writes a message to stdout using the Linux syscall API.
  • main.c - a tiny C driver used only to invoke the Linux assembly routine three times.
  • hello_windows.asm - a NASM x86-64 Windows console program that writes a message using the Windows API.
  • hello.o - compiled Linux NASM object file (generated).
  • hello - compiled Linux executable (generated).
  • hello_windows.obj - compiled Windows NASM object file (generated).
  • hello_windows.exe - compiled Windows executable (generated).

What it does

The Linux example is implemented in hello.asm, and main.c calls print_arken() three times to exercise that routine.

The Windows example is implemented in hello_windows.asm and writes directly to standard output with GetStdHandle and WriteFile.

Both examples print:

Hello, World!

Requirements

Linux example

  • Linux x86-64 environment or WSL (Windows Subsystem for Linux)
  • nasm
  • gcc

hello.asm is written for Linux x86-64 and uses syscall, so it is not directly compatible with native Windows.

Windows example

  • Windows PowerShell or another native Windows shell
  • nasm
  • gcc from MinGW-w64 or a compatible Windows GCC toolchain

hello_windows.asm uses the Windows x64 calling convention and calls functions from kernel32.

Build and run

Linux example

From the repository root in WSL or Linux:

nasm -f elf64 hello.asm -o hello.o
gcc main.c hello.o -o hello
./hello

If you want to avoid PIE-related linker warnings, use:

gcc -no-pie main.c hello.o -o hello

Windows example

From the repository root in PowerShell:

nasm -f win64 hello_windows.asm -o hello_windows.obj
gcc hello_windows.obj -o hello_windows.exe -lkernel32
.\hello_windows.exe

Notes

  • The assembly uses RIP-relative addressing for the message data.
  • Use the Linux commands from WSL or Linux and the Windows commands from PowerShell. Mixing the two toolchains will fail at link time.
  • If you rebuild the project, you can safely delete generated outputs such as hello.o, hello, hello_windows.obj, and hello_windows.exe before rerunning the build commands.

About

A hello world program in assembly x86 for linux.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors