NASMusage is a Windows x86-64 learning repo for combining NASM assembly with C. The main project is a small TCP networking probe: C handles Winsock networking, while NASM routines process the received bytes with low-level buffer operations.
- Windows x64 calling convention between C and NASM
- Building NASM object files and linking them with C
- Winsock TCP connection setup from C
- Passing network buffers into assembly routines
- Byte-level checksum, byte counting, and in-place ASCII transformation in NASM
- Cleaner project structure for small mixed-language systems programs
include/
net_asm.h C declarations for NASM routines
src/
tcp_probe.c Winsock TCP client demo
net_asm.asm Assembly helper routines used by the client
examples/
hello.asm Minimal printf example
console_grid.asm Windows console rendering demo
build.ps1 PowerShell build script
build.bat Batch build script
LICENSE GPL-3.0 license
- Windows
- NASM
- GCC/MinGW-w64 or another C compiler that can link with Winsock
Make sure both nasm and gcc are available on your PATH.
Using PowerShell:
.\build.ps1Using Command Prompt:
build.batManual build command:
nasm -f win64 src\net_asm.asm -o build\net_asm.obj
gcc src\tcp_probe.c build\net_asm.obj -Iinclude -lws2_32 -o build\tcp_probe.exeDefault target:
.\build\tcp_probe.exeCustom host, port, and path:
.\build\tcp_probe.exe example.com 80 /The program sends an HTTP HEAD request, receives the first response chunk, and then calls NASM routines to:
- calculate a 32-bit additive checksum
- count newline bytes
- uppercase the response preview in place
The C program calls these NASM functions:
uint32_t asm_checksum32(const uint8_t *buffer, size_t length);
size_t asm_count_byte(const uint8_t *buffer, size_t length, uint8_t value);
void asm_uppercase_ascii(char *buffer, size_t length);These functions follow the Windows x64 ABI:
RCX,RDX,R8, andR9hold the first four integer or pointer argumentsRAXholds the return value- caller-saved registers may be overwritten
Build the hello example:
nasm -f win64 examples\hello.asm -o build\hello.obj
gcc build\hello.obj -o build\hello.exeBuild the console grid example:
nasm -f win64 examples\console_grid.asm -o build\console_grid.obj
gcc build\console_grid.obj -o build\console_grid.exe -lkernel32 -lmsvcrtThis repo is intentionally small and educational. The networking code is kept in C because Winsock setup is clearer there; the assembly focuses on data-processing routines where register usage, pointer arithmetic, and ABI details are easier to study.
This repository is licensed under the GPL-3.0 license. See LICENSE for details.