ZASM Basic Examples
Documentation home ยท Language reference
Save each complete program under the suggested filename. Run the commands from
the extracted compiler folder, keeping include beside zero.exe and zcc.exe.
All examples target Windows x86 and use only the currently implemented forms.
Print Text
Save as hello-text.zasm:
using "windows/console.zh"
jmp start
message db 'Hello Zero!', 0
start:
push message
call [puts]
add esp, 4
push 0
call [exit]
.\zero.exe run hello-text.zasm
Output:
Hello Zero!
DB stores the string and terminating zero. puts prints it and adds a newline.
add esp, 4 removes the argument after the cdecl call.
Add Two Integers
Save as add-integers.zasm:
using "windows/console.zh"
jmp start
format db '7 + 5 = %d', 10, 0
start:
mov eax, 7
add eax, 5
push eax ; Value for %d.
push format ; First argument: format string.
call [printf]
add esp, 8 ; Remove both 4-byte arguments.
push 0
call [exit]
.\zero.exe run add-integers.zasm
Output:
7 + 5 = 12
The addition happens in EAX. printf formats the calculated value as decimal
text; it does not evaluate the expression in the string. If you change the numbers,
update the descriptive text too. The shipped
arithmetic sample
also multiplies using repeated addition because MUL is not implemented yet.
Show a Windows MessageBox
Save as hello-messagebox.zasm:
using "windows/windows.zh"
jmp start
message db 'Hello Zero!', 0
caption db 'Zero', 0
start:
push 0 ; MB_OK.
push caption
push message
push 0 ; No parent window.
call [MessageBoxA]
push 0
call [ExitProcess]
.\zero.exe run hello-messagebox.zasm
A dialog titled Zero displays Hello Zero!. Click OK to exit.
Arguments are pushed right to left. These Win32 functions clean up their own
arguments, so no add esp, ... follows the calls. The executable still uses the
console subsystem; this example does not select a separate GUI subsystem.
Next Steps
- Include guide: put shared source in
.zhfiles and use custom-Ipaths. - String concatenation tutorial: print separate strings, then join them with a space.
- Sample guide: explore the full sample collection, including editable Windows controls.
- Instruction reference: choose supported operand forms.
Coming Soon
- Loops: explain comparison flags and a counted loop step by step.
- Procedures: introduce local calls, stack arguments, return values, and register preservation.
- Writable buffers: walk through stack allocation and safe buffer sizes.
- Windows controls: explain message handling, callbacks, and the controls sample.
- Higher-level Zero: add the first runnable
.zsrctutorial when compilation is implemented.