CSC103 Homework 4 solution 2012
--D. Thiebaut 09:51, 1 March 2012 (EST)
; Solution program for optional assignment
; Spring 2012
; D. Thiebaut
start: lod-c 55 ; load 55 in AC
sto var1 ; store AC in var1 and var2 variables
sto var2
loop: lod var2 ; get var2 into AC
sub-c 2 ; subtract 2 from AC
sto var2 ; store AC in var2. Var2 has been
; decremented by 2!
lod var1 ; get var1 into AC
add-c 2 ; add 2 to AC
sto var1 ; store AC in var1. Var1 has been
; incremented by 2!
; if AC contains 65, it means that we
; have done all the work we wanted. So
; we can stop the loop. If we subtract
; 65 from AC, the result will be 0 in AC
; and the JMZ will let us jump out of the
; loop. If AC is not 65, subtracting 65
; from it will not result in it containing
; 0, and we'll continue the loop.
sub-c 65 ; if AC contains 65, AC becomes 0
jmz done ; if AC is 0, jump to label done
jmp loop ; otherwise, jump to label loop
done: hlt ; we're done! Stop!
@15 ; we have to make sure that the program
; contains fewer than 15 instructions, otherwise
; we should set this number higher.
var1: data ; our 2 variables.
var2: data