ecall
ecall

ecall is how your program asks the outside world to do something for it. On its own, assembly code can add numbers and move them around, but it cannot directly touch the screen, the keyboard, or any device — those belong to the system your program runs inside. ecall, short for environment call, is the doorway to that system: it pauses your code and asks the host (an operating system on real hardware, or this simulator here) to perform a service, then hands control back.

Because there are several services, you have to say which one you want. The convention is to put a service number in the register a7, put any data the service needs in a0, then run ecall. This simulator offers: 1 to print the integer in a0, 4 to print text whose address is in a0, 5 to read a number from input into a0, 10 to end the program, and 32 to pause for a0 milliseconds.

So printing a number is three steps: load 1 into a7 to pick the print service, load the number into a0, and ecall. That is exactly the example. Every program also needs to end deliberately, which is why these lessons close with li a7, 10 then ecall — without it, the processor would keep running past your last line into whatever happens to follow.

This same idea scales up to real systems: a full operating system works the same way, just with a longer menu of services. What changes is the list, not the doorway.

li a7, 1     # service 1 = print integer
li a0, 42
ecall        # prints 42