MMIX has several types of branches and jumps, which allow us to build complex and flexible programs. They help programmers to organize fork and cycle constructions as well as call subroutines.
You probably know that there are several types of branch instructions in computers. They may be conditional and unconditional for instance: the first ones are executed only under definite condition, and the last - every time. When address to go is specified directly in an instruction, such branch is absolute and programmers usually call it jump. But there is also another kind of commands often embraced into modern CPU's instruction set. They are named relative branches because show the position of next command relatively to current one. Practically they add a parameter (displacement) from the branch instruction to current value of processor program counter. The relative instructions are less demonstrative, but much more universal: they can work correctly without changes in any memory area. This property is very important for modern multitask computers, which have to load software dynamically to free memory addresses.
We must also mentioned one more instruction type - subroutine calls. Their main feature is the possibility to organize return to main program after subroutine's execution. Differnt methods can be used for this purpose.
MMIX, being the processor of the new millennium, has wide set of branch instructions. The main kinds of such instruction are the following:
- relative conditional branches with codes 40-4F and 50-5F using 2-byte bias
- 32 conditional move instructions with codes 60-7F
- 2 unconditional relative jump instructions (F0 - forward, F1 - backwards) with 3-byte bias
- 2 modifications of unconditional absolute jump with possible return (9E, 9F);
allow to organize "old-fashioned" subroutine call
- some special instructions to call subroutine with parameters using MMIX hardware stack of registers
- TRAP (code 00) and TRIP (FF) instructions - specialized subroutine calls for system purposes;
TRAP 0 returns control to operating system, TRAP 1 is an entry to "rudimentary" input/output operations
In E-MMI software TRAP 5 is used for I/O operations (do you remember famous CP/M with CALL 5 for system actions?!)
Related topics:
"MMIX basics" page