Professional Documents
Culture Documents
Note: A is an address; acc stands for accumulator; @A means contents of address A; PC is program counter, N -
number, S - string
1 Output a message.
2 Read two numbers m and n and output the larger number.
3 Read two numbers m and n and output the product of the
two numbers.
4 Read two positive integers m and n and output mn .
5 Read two positive integers m and n and output the largest
number that divides both m and n.
We write VSC code for the first three.
Problems 4 to 5 are for you to practice in lab 1, Q3.
Example of VSC program - 1
Example 1
A VSC program that prints Very Simple Computer.
Address Instn. code Optional operand Comment
0 1 #start
1 4 ”Very Simple Computer” #load string in acc
2 14 #output contents of acc
3 15 #output newline
4 0 #halt
Example of VSC program - 2
Example 2
A VSC program that reads two numbers and prints the larger of
the two numbers.
Address Instn. code Optional operand Comment
0 1 #start
1 12 #Read first number, acc=n1
2 5 500 #Store n1 at addr 500
3 12 #Read second number, acc=n2
4 5 501 #Store n2 at 501
5 7 #n2 is negated, acc=-n2
6 6 500 #add n1, acc=n1-n2
7 11 14 #n1 is larger, jmp+ to 14
8 2 501 #n2 ≥ n1, load n2, acc=n2
9 14 #output acc
10 4 ” is larger or equal.” #load string, acc=”is larger or equal”
11 14 #output string
12 15 #output newline
13 0 #halt
14 2 500 #n1 > n2, load n1, acc=n1
15 8 9 #jump to addr 9
Example of VSC program - 3
Example 3
m n m − n (assuming m > n)
64 36 28
36 28 8
28 8 20
20 8 12
12 8 4
8 4 4
4 4 m = n, terminates, GCD=4