XSM Execution Environment
- 20 General Purpose Registers (R0-R19)
- Stack pointer, Base pointer, Instruction Pointer
- 5120 words address space


Text Size, Data Size, Heap Size and Stack size indicates the sizes of Text, Data, Heap and Stack regions to be allocated by the OS loader when the file is loaded for execution.
The present eXpOS virtual address space model requires that the data and stack must be in the same memory area and must be managed by the compiler / application program (this means that the program must contain the code to initialize the value of the stack pointer). The value of Data Size field is ignored. Moreover, the eXpOS loader sets the size of text region to 2048 words and stack region to 1024 words in memory irrespective of the values present in the header.
If the Runtime Library must be included when the file is loaded, the Library Flag is set to 1 in the executable file. If this flag is not set then neither memory is allocated for the heap nor the library linked to the address space of the process at execution time.
MOV Ri, Rj # register addressing
MOV Ri, INTEGER/STRING # immediate addressing
MOV Ri, [Rj] # register indirect addressing
MOV [Ri], Rj
MOV [LOC], Rj # Direct addressing
MOV Rj, [LOC]
OP Ri, Rj
OP Ri, INTEGER # add, sub, mul, div, mod
OP Ri # INR, DCR
OP Ri, Rj # LT, GT, GE, LE etc.
JZ Ri, target_address
JNZ Ri, target_address
JMP target_address
PUSH Ri # SP <- SP+1, Memory[SP] <- Ri
POP Ri # Ri <- Memory[SP], SP <- SP-1
Subroutine Instructions
These instructions manage program control flow for subroutines, using the stack to save and restore the return address. Each instruction is two memory words long.
CALL target_address/Register # Memory[SP] <- IP + 2, IP <- target_address
RET # IP <- Memory[SP]
SP <- SP-1
BKRP -> Debug mode
INT 6 -> Read INT 7 -> Write INT 10 -> Exit
- Headers must be set, so for each xexe file, 8 words are reserved
0 2056 0 0 0 0 0 BKRP MOV R0, 3 MOV R1, 2 ADD RO, R1
Command
./xsm -l library.lib -e target_file.xsm --debug
System Calls
- Printing a number is a privileged operation
- The return values must be pushed into the stack
MOV SP, 4095 # SP increments immediately before a PUSH Operation
For example
| Order | Assembly Code | Value/Source | Purpose |
| 5th Word | MOV R2, 5 then PUSH R2 | 5 | System Call Number: Tells the kernel which service to run (Write is 5 in the argument convention, not the interrupt number 7). |
| 4th Word | MOV R2, -2 then PUSH R2 | -2 | Argument 1: File Descriptor (conventionally -2 for console Write). |
| 3rd Word | PUSH R0 | The 5 from R0 | Argument 2 (The Data): The actual data value (5) to be printed. |
| 2nd Word | PUSH R2 | R2 (Blank) | Argument 3: A blank argument/placeholder. |
| 1st Word | PUSH R2 | R2 (Blank) | Storage for Return Value: A placeholder where the kernel will write the system call's return code (0 for success). |
After that interrupt call, the stack must be cleared.
| System Call | System Call Number | Interrupt Routine Number | Argument 1 | Argument 2 | Argument 3 | Return Values |
|---|---|---|---|---|---|---|
| Read | 7 | 6 | -1 | Buffer (int/str)* | - | 0 - Success |
| -1 - File Descriptor given is invalid | ||||||
| -2 - Read error | ||||||
| Write | 5 | 7 | -2 | Data+ | - | 0 - Success |
| -1 - File Descriptor given is invalid | ||||||
| Exit | 10 | 10 | - | - | - | - |