Computer Science 161.01
Professor Valente
October 4th 2017
A VSC-32 Looping
Example!
Here’s a program that reads in a series of integers (as many as the user wishes!) and sums them all.
The program terminates as soon as the user enters 0.
Assembly Language à Machine Language The program in hex!
top: read x 01101010 6A2AE7AB4B29E08B00000000
load x 00101010
jump ahead 11100111
add sum 10101011
store sum 01001011
load zero 00101001
jump top 11100000
ahead: write sum 10001011
stop 00000000
zero: data 0 00000000
x: data 0 00000000
sum: data 0 00000000
The new instruction here is jump. It jumps to the instruction with the specified label only if the accumulator has 0 in it.
If the accumulator has a value other than 0 in it, the jump is not done, and the program proceeds with the next instruction.
For example, the following program will read x, load x into the accumulator.
If that value is 0, the jump ahead instruction will cause a jump to the instruction labeled ahead,
in other words the instruction write sum.
If that value was not 0, no jump is performed, and the next instruction add sum is done,
since it is just below jump ahead.
If you understood the above paragraph, you should then look carefully at the other jump instruction in the program,
which is preceded by load zero.
Why is load zero just prior to this jump instruction?
What will this jump instruction always do, therefore?
You might try entering the hex (quickest way) into the appropriate VSC-32 site to see how the program works.
Remember, as you run to program, to keep entering integers, and then enter 0!