Anda di halaman 1dari 5

CS 240 Computer Systems and Networks

Prof. Irv Englander


Fall 2016
Due Wednesday 5, October at 11:59 PM
Homework Assignment 3

This assignment is again separated into two parts. Part [A] is intended to give
you practice at working with the Little Man instruction set and with the LMC
VVM simulator. Each of the exercises in part [A] emphasizes a different aspect
of machine language programming, so you will want to do them all. You are
strongly encouraged to work directly with your CS240 partner on the part
[A] problems. The problems are graduated to help you ease your way into
Bloom Level 3.
In each case you should determine the algorithm first, then write the
code, then test it using the VVM simulator. (Definitely not the other
way around!)
Part [A]

1. The Little Man Computer tab on Blackboard contains the install


file for the LMC that you will use, along with installation instructions
and some useful documentation. Get the LMC installed on your
laptop and experiment with it, until you're comfortable with your
ability to enter, execute, and test programs.
2. Write a Little Man program that takes two input values and
outputs the absolute value of the difference between the two inputs.
For example, the input values 5 and 3 give output 2. Input values 3
and 5 also give output 2.
901
310
901
311
210
812
510
211
902
000

3. Write a Little Man program that takes NO input, but simply


outputs ten consecutive values that double, starting from 1: 1, 2, 4,
8, ... etc. This can be done easily by storing 1 as a data value (i.e.
you dont have to input it. Just put it in a mailbox somewhere.) and
adding the previous output value to itself to create the next output.
Use an index variable that you set initially to 10 (again you can
simply put this into your program) and count down to test for zero
as a way to stop.

599
902
199
902
398
198
902
397
197
902
396
196
902
395
195
902
394
194
902
393
193
902
392
192
902
391
191
902
390
000
*99
001

If you prefer, you can write a program that outputs the Fibonacci
series instead. The Fibonacci series starts with 0, 1. Each output
value after that is the sum of the previous two. [0, 1, 1, 2, 3, 5, 8,
13, ...]
4. Write a program that takes in a series of input numbers and
outputs the sum of all the previous numbers, including the current
one, each time there is a new entry. Your program will stop when the
user inputs a zero. (There is no limit to the number of values that
the user will input.) Example: Input is 2, 3, 5, 1, 8, 0. Output is 2, 5,
10, 11, 19.
901
399

901
199
398
901
198
397
901

5. Write a program that takes in a series of input numbers and


outputs the sum of each pair of input numbers. Your program will
stop when the user inputs a zero. Example: input is 3, 5, 9, 4, 16, 0.
Output is 8, 14, 13, 20.
901//INPUT3
399//STORE3IN99
901//INPUT5
398//STORE5IN98
199//ADD3TO5
902//OUTPUT8
397//STORE8IN97
901//INPUT9
396//STORE9IN96
198//ADD5TO9
902//OUTPUT14
395//STORE14IN95
901//INPUT4
394//STORE4IN94
196//ADD4TO9
902//OUTPUT13
393//STORE13IN93

6. This ones a challenge problem, but if you and your partner can
figure it out, you are well on your way to being a professional: Write
a program that accepts two input values and outputs the product
(multiplication) of the two. Hint: use one of the values as an index to
count the number of times that you add the other value to itself.
Part [B]

You are to solve this problem completely on your own, with no help
from anyone except the instructor!

INP//INPUTA
STO99//STOREAIN99
INP//INPUTB
STO98//STOREBIN98
LDA99//.LOADAINTOCALC
SUB98//SUBTRACTBFROMA
BRZ

1. Write a Little Man program that takes in two values.


2. You may assume that both values are positive and that the
first value is always larger than the second.
3. The program will determine if the second number divides
evenly into the first.
4. If it does, the program outputs the value 0.
5. If not, the program outputs a replacement for the first number
that represents the next positive value that would divide
evenly by the second number.
6. The program will continue to accept pairs of numbers and
produce appropriate outputs until the user enters 0,0 as the
input pair.
Examples:
input is 80, 16.
Output is 0.
Input is 53, 12
. Output is 60.
Input is 15, 2. Output is 16.
Input is 0, 0.
Program stops without producing output.

Test your program thoroughly. Submit your code as a text file or


.vvm file, NOT as a .doc or .docx file. Submit your code through the
link given. Your solution is due on Wednesday, October 5h at 11:59
P.M. You must include a comment at the end of your code that
attests that your solution is yours and yours alone, done without
help from anybody except the instructor.
(Note: you may have to use Internet Explorer to submit your file. I'm
told that the Chrome link is flaky, and only works sometimes. If the
submit system doesn't work at all, and you are truly desperate, you
may submit your file to me as an email attachment, with the email

title Assignment 3 in desperation. Please do not do this unless you


are truly desperate! )

INP//INPUTA
STO18//STOREAIN18
STO17//STORE1IN17
INP//INPUTB
STO19//STOREBIN19
LDA18
SUB19
BRZ90
BRP06
STO16
LDA18
SUB16
OUT
BR15
ADD17
STO20
OUT
HLT
*90
OUT
BR00
HLT

Anda mungkin juga menyukai