Showing posts with label Assembly. Show all posts
Showing posts with label Assembly. Show all posts

Friday, September 12, 2025

Hello world assembly on x86 Linux

Hello world assembly on x86 Linux

Save code below as hello.asm
global _start

section .data
message: db 'hello, world!', 10

section .text
_start:
    mov     rax, 1          ; system call number should be stored in rax
    mov     rdi, 1          ; argument #1 in rdi, where to write (description)?
    mov     rsi, message    ; argument #2 in rsi, where does the string start?
    mov     rdx, 14         ; argument #3 in rdx, how many bytes to write?
    syscall                 ; this instruction invokes a system call

    mov     rax, 60         ; 'exit' syscall number
    xor     rdi, rdi
    syscall
Now assemble/build the file
nasm -felf64 hello.asm -o hello.o
Link to create executable
ld -o hello hello.o
Run it
u1@v1vm10:~$ ./hello 
hello, world!

Monday, March 23, 2020

ASM: Convert DWORD to string in Assembly using MSVCRT _ultoa

This post shows how to convert unsigned int (DWORD) to string using MSVCRT function _ultoa.



Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff int2string3.asm

To link:
\masm32\bin\Link /SUBSYSTEM:CONSOLE int2string3.obj
Keywords: Assembly, Win32

Saturday, March 14, 2020

ASM: Convert int to string in Assembly part 2

This post shows how to convert int (DWORD) to string using modified version of dwtoa(dwtoa2) from MASM library. Older post can be found here.



Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff int2string2.asm

To link:
\masm32\bin\Link /SUBSYSTEM:CONSOLE int2string2.obj

ASM: Convert int to string in Assembly

This post shows how to convert int (DWORD) to string using MASM library dwtoa. There seems to be a bug in dwtoa as it can only handle 2147483647 instead of 4294967295 which is the maximum size of DWORD (32-bit). The code for dwtoa checks for a negative number which is not needed for DWORD. Note that DWORD is defined as 32-bit unsigned.



Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff int2string.asm

To link:
\masm32\bin\Link /SUBSYSTEM:CONSOLE int2string.obj

Tuesday, March 10, 2020

ASM: Basic Windows application in Assembly

This post shows how to create Windows application using Assembly.



Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff basicwindows.asm

To link:
\masm32\bin\Link /SUBSYSTEM:WINDOWS basicwindows.obj

Reference(s):
This is shamelessly using contents from Windows Assembly Programming Tutorial  by JEFF HUANG (huang6@uiuc.edu)

Monday, March 09, 2020

ASM: Basic usage of assembly instructions

This program shows usage of basic assembly instructions add, cmp, dec, jnz, jz, mov, mul, pop, push, xor



Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff basicinstructions.asm

To link:
\masm32\bin\Link /SUBSYSTEM:CONSOLE basicinstructions.obj

Reference(s):
This is shamelessly using contents from Windows Assembly Programming Tutorial  by JEFF HUANG (huang6@uiuc.edu)

Friday, March 06, 2020

ASM: Hello world using MessageBox in Windows assembly

MessageBox Hello World in Windows assembly using MASM


Pre-requisite:

To assemble:
\masm32\bin\ml /c /Zd /coff hellow.asm

To link:
\masm32\bin\Link /SUBSYSTEM:WINDOWS hellow.obj

Reference(s):
This is shamelessly using contents from Windows Assembly Programming Tutorial  by JEFF HUANG (huang6@uiuc.edu)
x86 Disassembly - link

Thursday, March 05, 2020

ASM: Hello world in Windows assembly

Hello world in Windows assembly using MASM



Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff hello.asm

To link:
\masm32\bin\Link /SUBSYSTEM:CONSOLE hello.obj

Reference(s):
This is shamelessly using contents from Windows Assembly Programming Tutorial  by JEFF HUANG (huang6@uiuc.edu)
x86 Disassembly - link

CPP Quick Guide

Basics Hello world User input While loop If statement For loop Switch statement Read file using ifstream Write to a file using ofstr...