Peer Eval of Group 1-6
By Group 1-1

Assembly Language

We do not understand the format of the data coming in from input in order to load it into INPUT.  For now, we  will assume that the command AIN knows how to parse the input data and store it into the specified input  register.

Also, we do not understand where the interrupt bit is stored, so we do not know what to check to see if an  interrupt has occured.  We will assume that the reserved register R7 holds this value and it is 1 if an  interrupt occurs.

# Register Usage
# R0	Zero
# R1	m
# R2	n
# R3	temp
# R4	a
# R5	b
# R6	One
# R7	Interrupt

Init	LLC	R6, 1	# Load the value 1 into R6

Init2	EQ	R7, R6, Init3	# Break out of the interrupt loop
	JP	Init2	# Continue the interrupt loop

Init3	LLC	RI, 0	# Reset the interrupt register to 0
	AIN	R1	# Load the input into R1
	LLC	R2, 2	# Load the value 2 into R2
	
Gcd	HMO	R4, R2	# a = n
	HMO	R5, R1	# b = m
	BT	R0, R5, Return	# If 0 >= b, jump to Return
	BT	R5, R4, Else	# If b <= a, jump to Else
	HMO	R3, R4	# temp = a
	HMO	R4, R5	# a = b
	HMO	R5, R3	# b = temp
	JP	Return	# Jump to Return

Else	SUB	R4, R5	# a = a - b

Return	EQ	R4, R6, Exit	# If a == 1, jump to Exit
	ADD	R1, R6	# m = m + 1
	JP	Gcd	# Jump to Gcd

Exit	AST	PORT3, R1	# Output to Port 3

Machine Code

LLC is not documented, we will assume bits 11:9 are RS and 8:0 are the immediate input.

0x000	1110110000000001	# Init

0x002	0100001000111110	# Init2
0x004	0101000000000100

0x006	1110111000000000	# Init3
0x008 1001000000000001
0x00A	1110010000000010

0x00C	1000000000100010	# Gcd
0x00E	1000000000101001
0x010	0011100010000101
0x012	0011100000101100
0x014	1000000000011100
0x016	1000000000100101
0x018	1000000000101011
0x01A	0101000000100010
0x01C	0010000000100101	# Else
0x01E	0100011100100110	# Return
0x020 0000000000001110
0x022	0101000000010000
0x024	1010000000011001	# Exit