Last active
December 27, 2025 01:29
-
-
Save jac18281828/0ec94ee36026036140ed3b20386c837d to your computer and use it in GitHub Desktop.
PowerOf2 MMIX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| LOC #100 | |
| % Entry point | |
| Main SETI $1,20 | |
| PUSHJ $0,IntegerPowerOfTwo % compute 2^$1 | |
| JMP Done | |
| % ---------------------------------------------------- | |
| % compute the power of 2 to the n where n is in $1 | |
| % result is returned in $0 | |
| % ---------------------------------------------------- | |
| IntegerPowerOfTwo | |
| SETI $0, 0 % initialize counter to 0 | |
| SETI $2, 1 | |
| CountLoop | |
| CMP $5,$0,$1 | |
| BZ $5,CountEnd | |
| MULUI $2,$2,2 % double the value in $2 each iteration | |
| ADDUI $0,$0,1 | |
| JMP CountLoop | |
| CountEnd | |
| SET $0,$2 | |
| POP 1,0 % return to caller (rJ) | |
| Done | |
| TRAP 0,Halt,0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment