This repository has been archived on 2022-08-01. You can view files and clone it, but cannot push or open issues or pull requests.
150ASM-Emulator/data/prog.scc
2020-06-23 22:56:38 +01:00

31 lines
539 B
Text
Executable file

# INITIALISE VARIABLES
SET REGA 4
SET REGB 610
SET REGC 0
# JUMP TO END IF A == 0
SET REGX REGA
JMP 28
# ELSE, HALVE A
SHR REGA 1
# DOUBLE B
SHL REGB 1
# CHECK IF A IS ODD
SET REGX REGA
AND REGX 1
# IF IT'S EVEN, CHECK IF A == 1
JMP 20
# ELSE, ADD B TO THE RESULT
ADD REGC REGB
# CHECK IF A == 1
SET REGX REGA
# JMP JUMPS ON A 0, NOT A 1
SUB REGX 1
# IF IT IS, JUMP TO THE END OF THE LOOP
JMP 28
# ELSE, JUMP TO THE BEGINNING OF THE LOOP
SET REGX 0
JMP 8
# PRINTS THE RESULT
PRT REGC
# EXITS THE PROGRAM
NOP