Computer
Science 161.01
Fall
2019
Homework
7 DUE Friday October 18th at 9:30AM
YOUR NAME:
____________________________________________________
1. (10 points) What follows is a VSC-32 assembly language
program. Recall that JUMP causes a jump
to occur to the specified labeled instruction only if the accumulator has 0 in it. If there is something other than 0 in the
accumulator, the JUMP does not take effect, and the program simply follows the
next instruction below it.
Without actually typing this program in to the web site, answer the
following:
a) What value will be written by the program if the number entered for X
by the
user is 7? ________
b) What value will be written by the program if the number entered for X
by the user is 0? ________
c) Assemble (that is, translate into binary) the first 4 instructions of
the program. Remember that each
instruction is 8 bits. Remember also
that the program gets loaded into memory beginning at address 0.
READ X
LOAD X
JUMP DONE
ADD THREE
STORE X
DONE:WRITE X
STOP
THREE: DATA 3
X:DATA 0
2. (5 points) The five VSC-32 instructions
LOAD X
ADD Y
ADD Z
SUBTRACT W
STORE X
can be replaced by one JavaScript assignment statement.
Write down the assignment statement: _________________________
3. (5 points) The JavaScript assignment statement Y = Z – W + Y would require four VSC-32 instructions. Write them in the space provided below.
4. (10 points) Get ready to decipher! This VSC-32 machine language program
writes
three different numbers to the
screen: 878827C8498900370F
What are those three values? (Do not use the software to find out)
5. (10 points) Without using the JavaScript scratchpad site, predict the values for
each of the following expressions:
7 + 10 * 5 __________________
29 % 7 __________________
100 – 30 % 5 __________________
(100 – 30) % 5 __________________
10 * 5 % 4 __________________
10 * (5 % 4) __________________
2 + 5 == 8 - 1 __________________
10 % 2 != 0 __________________
itsOctober = true;
itsOctober && (5 < 2) __________________
itsTuesday = false;
(10 % 2 == 1) || !itsTuesday __________________
6. (10 points) The following JavaScript program prompts for and reads some number of minutes and some number of seconds, then computes and displays the total number of seconds to the screen. Extend the program so that it reads some number of hours as well, then computes and displays the total number of seconds. (There are 3600 seconds in each hour.)
Here is what you should do.
First, copy and paste the following into the scratchpad site.
See that it works as expected.
mins = prompt("How many
minutes?");
secs = parseInt(prompt("How
many seconds?"));
total = 60*mins
+ secs;
alert("Total seconds = "
+ total);
Then, modify the above program while at the scratchpad site so that it works according to the above instructions.
When your program finally does work as expected, copy and paste it from the scratchpad and email it to me.