Preview

03 - LMC #1

 1. The LMC was designed to model a very bsaic Von Neumann computer's CPU.

  FALSE

  TRUE

 2. Why use low level languages at all?

  A compiler may not be required (although an assembler would) which could mean the program is much faster

  Hardware drivers and embedded systems (e.g coding in a washing macine) require directly accessing hardware for which low level languages are perfect

  All of the listed statements are valid answers

  because they allow direct access to the processors and IAS locations

 3. Although an actual computer uses binary numbers, the LMC instruction values tend to be in decimal, for simplicity.
The LMC assembly language is used to instruct the simulated machine, step by step.

  TRUE

  FALSE

 4. The accumulator in a LMC ____________________________________.

  holds a value and stores it permanently in ROM

  does not hold any values but can register commands and operators

  holds a value for a single clock second before passing it on to the output register

  holds a temporary value that is manipulated by operations such as odd and subtract

 5. Values are stored in memory locations called ___________, this includes the program itself. They are referred to by location, ranging from location 00 to location 99.

  cache chips

  program counters

  registers

  RAM chips

 6. What does the program counter do?

  holds the value of the accumulator (making a direct copy of any value held there)

  holds the address of the first instruction (which is always address 00)

  holds the value that is passed on to it from the special registers. It then alerts the program to this value's existence

  holds the address of the next instruction (lowest address 00, highest address 99)

 7. What does the instruction regsiter do?

  It is purely ornamental as the LMC does not make use of it

  It holds the operators that come in to the program via the program counter

  It holds the top digit of the instruction just read from memory

  It holds the values that are held in the accumulator, making a backup copy for security purposes

 8. The LMC instruction set is made up of 11 mnemonics, ten of which have a numeric code to model machine code. What are the three memory operators?
Advanced_LMC_1_question1.png

  MORE, INP, DAT

  STORE, LOAD, DAT

  INP, OUT, DAT

  STORE, INP, OUT

 9. Referring to the image above, what are the two input-output operators?

  INP, OUT

  INP, STORE

  DAT, INP

  DAT, STORE

 10. In reference to this LMC, fill in the blanks for 1,2 and 3.
http://peterhigginson.co.uk/LMC/
Advanced_LMC_1_question2.png

  1. 902 2. STA 3. HLT

  1. HLT 2. STA 3. 902

  1. 001 2. STO X 3. STOP

  1. 100 2. HLT 3. STA

 11. Note the pseudocode for an assembly language program below. What does it do?
INP a value
STA Store it under a label identifier
INP another value
ADD this value to the first value
OUT Output the value
HLT Stop the program
Declare the labels 

  Adds multiple numbers (any numbers that are input) together and outputs the total result

  Stores two numbers in the accumulator and halts the program

  Takes a single number and adds it to the value (which is 0) in the accumulator. Result is output

  Adds two numbers together

 12. The instruction set for the LMC simulator has only ADD and SUB arithmetic operations. There is no multiplication or MUL instruction.
Early model CPUs did not have a MUL instruction, although the more modern CPUs now do have this feature integrated.

  TRUE

  FALSE

 13. Multiplication using just ADD and SUB ____________________________________.

  cannot be achieved.

  could be achieved using the division operator, if it is present

  could be achieved through a series of additions and alternate subtractions

  could be achieved through a series of additions

 14. In LMC, some programs may require a loop. What would you use to break out of the loop?

  INP AND DAT operations

  HLT and AND commands

  BRA and BRZ operations

  901 and 900 commands

 15. Assembly language doesn't have if statements and comparison operators. Instead it would:
num1 = int(input("Enter a number 1: "))
num2 = int(input("Enter a number 2: "))
if (num1>num2):
	print(num2)

  add the two numbers to see if the sum is either positive or negative and in so doing determine the higher number

  multiply the numbers together and then divide by 2 to see which number is higher

  divide the two numbers by 2 and then add them together to see which number is higher

  subtract the two numbers to see if the sum is either positive or negative and in doing so determine which one is higher

 16. The following code outputs the higher of two input numbers. What are label 1 and 2?
     INP 
     STA num1
     INP another value
     STA num2
     SUB num1
     BRP label1
     LDA num1
	     BRA label2
label1     LDA num2
label2	OUT
	     HLT
num1		DAT
num2		DAT

  They are the equivalent of comparison operators in a high level language

  They are virtual labels which means they do not actually exist but are just theoretical

  They are label identifiers, a bit like a variable identifier in the python language

  They are hardware stops - labels that tell the program when to halt

 17. What does the following code do?
loop
x = 10
sub 1
store x
output x
Branch if Zero to STOP
Branch to loop
STOP halt
Declare the labels x 
Declare the labels for 1

  It starts at 0 and counts up to 10

  It produces a countdown effect starting at 10 and going down to 1

  It takes the number 10 and adds it to every other input number that enters the system

  It adds two numbers together up until the value of 10

 18. Refer to the code below and give a reason as to why it will not assemble and what lines need to be added to ensure execution.
INP
STA NUMA
INP
STA NUMB
SUB NUMA
BRP LABEL
LDA NUMB
BRA STOP
LABEL 	LDA NUMA
STOP 	OUT
HLT

  The INP command has been duplicate, which will confused the whole program

  The STOP OUT command should be right at the end

  The BRP LABEL should be repeated at least three times for execution to occur

  NUMA and NUMB have not been declared as labels. Add: NUMA DAT, NUMB DAT

 19. Analyse the following code and select the option that is most correct, in reference to this code.
loop    LDA x
        SUB one
        STA x
        OUT
        BRA loop
        HLT
x       DAT 10 
one     DAT 1

  The HLT and the OUT are in the wrong places. They should swap with each other and additional BRA be added to the start

  There is no break out of the loop. BRZ to OUT would be needed using a suitable label

  The loop is broken out of too early with BRA loop

  The HLT should come much later, at the end of the progarm

 20. In LMC and assembly code, complexity can be built up by combining loops with __________.

  comparison operators

  branching

  division

  addition