Random Access Machine Emulator

Fork me on GitHub
EKM
LKM
; R0 = base ; R1 = exponent GZ R1, exp_zero ;if R0^0 goto this special case R2 = R0 ;remember the base for every iteration R1 = R1 - 1 ;decrease the counter, because the loop should run only R1 times. while: GZ R1, ende ;loop until R1 is zero R0 = R0 * R2 ;multiply the current value with the start value of R0 R1 = R1 - 1 ;decrease the exponent GOTO while ;goto to the head of the loop exp_zero: R0 = 1 ;Case R0 ^ 0 ende: R1 = 1 ;set exponent to 1 to ensure that R0 will not change HALT ; R0 = R0 ^ R1