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.

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

Coming Soon