Your First Program
Let us begin with the smallest pleasant thing: printing a character.
LDI 72
PRT
HLT
What happens here
LDI 72loads the decimal value72into registerAPRTwrites the byte inAto outputHLTstops the machine
Since ASCII character 72 is H, the program prints H.
The same program written in hexadecimal looks like this:
LDI $48
PRT
HLT
A slightly friendlier example
The repository includes a full string-printing example in
examples/hello.s32.
Here is the heart of it:
LDP text
JSR printstr
HLT
printstr:
@loop:
LDA
CMI $00
JEQ @done
PRT
IDP
JMP @loop
@done:
RET
This shows a very typical T32 pattern:
DPpoints at some dataLDApulls the current byte intoA- a compare sets flags
- a conditional jump decides what to do next
Why this example matters
Even this tiny string printer demonstrates several important ideas:
- memory is read through
DP Ais the value you compute with and print- flags let you make decisions
- subroutines let you reuse code without adding more registers