Skip to content

Instantly share code, notes, and snippets.

@jac18281828
Last active December 27, 2025 01:29
Show Gist options
  • Select an option

  • Save jac18281828/0ec94ee36026036140ed3b20386c837d to your computer and use it in GitHub Desktop.

Select an option

Save jac18281828/0ec94ee36026036140ed3b20386c837d to your computer and use it in GitHub Desktop.
PowerOf2 MMIX
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