Computer Science 161.01

Fall 2018

A VSC-32 program that Counts


A VSC-32 Counting Example!

For our second looping example, we have a program that reads an integer from the user and counts up to whatever that integer is.

 

 

Assembly Language              Comments

 

read n                  Reads in some number n             

top: load n             Loads n into accumulator

subtract count          Subtracts current count from it (initially 0)

jump ahead              If accum has 0,jump to end of program (count=n)

load count              Otherwise load value of count       t

add one                 Add 1 to it

store count             Store it back as new count value

write count             Write the new count value

load zero               Load a 0 into accum

jump top                which forces us to jump back to top!

ahead:stop              STOP

count:data 0            count initially 0

one:data 1              one is 1

zero:data 0             zero is 0

n:data 0                n is initially 0

 

 

The Same Program Assembled into Machine Language

 

01101110                read into address 14!

00101110                …etc

11001011

11101010

00101011

10101100

01001011

10001011

00101101

11100001

00000000

00000000

00000001

00000000

00000000

 

The Same Program Shown in Hex Shorthand

 

6E2ECBEA2BAC4B8B2DE10000010000 

 

You should try entering the hex into the appropriate VSC-32 site to see how the program works.