Talking to the CPU directly
Every program you've written becomes assembly in the end: a list of tiny instructions the CPU runs one by one. In this course you'll write real RISC-V — the open instruction set used in everything from microcontrollers to phones — on a simulated 32-bit machine right in your browser.
There are no variables, only 32 registers — a0, t0, sp and friends — each holding one 32-bit number, plus memory. Press Run on the example and look at the registers underneath.
.data greeting: .asciz "Namaste, RISC-V!\n" .text main: la a0, greeting # a0 = address of the text li a7, 4 # service 4: print a string ecall li t0, 7 li t1, 5 add a0, t0, t1 # a0 = 7 + 5 li a7, 1 # service 1: print an integer ecall li a7, 10 # service 10: exit ecall
Reading a line of assembly
- li t0, 7 — load immediate: put the number 7 in t0.
- add a0, t0, t1 — destination first: a0 = t0 + t1.
- la a0, greeting — load the address of a label.
- ecall — ask the environment for a service; a7 says which one (1 print int, 4 print string, 11 print char, 10 exit).
a registers carry arguments and results, t registers are scratch space. Anything after # is a comment.