24
LMC – Controlled Assessment Contents Question 1:............................................... 2 Question 2:............................................ 3 Question 3) i)......................................... 5 Question 3) ii)........................................ 5 Question 3) iii)....................................... 6 Question 4) i)......................................... 8 Question 4 ii)........................................ 15 Question 5)........................................... 19 Question 6)........................................... 20

Controlled Assesment Little Man Computer

Embed Size (px)

Citation preview

Page 1: Controlled Assesment Little Man Computer

LMC – Controlled Assessment

ContentsQuestion 1:...........................................................................................................................2

Question 2:...................................................................................................................3Question 3) i)...............................................................................................................5Question 3) ii)..............................................................................................................5Question 3) iii).............................................................................................................6Question 4) i)...............................................................................................................8Question 4 ii).............................................................................................................15Question 5).................................................................................................................19Question 6).................................................................................................................20

Page 2: Controlled Assesment Little Man Computer

Question 1:

User enters input

Provides user with an output

Shows the program has been successfully compiled

Variable DEC’s location

Page 3: Controlled Assesment Little Man Computer

Question 2:

Line number Code Explanation0 INP Asks the user for an input1 STA DEC Stores the input and declares it as a

variable called DEC2 INP Asks the user for a second input3 LOOP SUB

DECSets the variable LOOP, loads the

variable called DEC to the accumulator and subtract the variable

DEC from the second input4 OUT Gives the user the output5 BRZ QUIT If the number is zero, set as the

variable QUIT6 BRA LOOP If the number is not zero, set variable

LOOP7 QUIT HLT Stop QUIT if reached zero and stop

process8 DEC DAT Store DEC in data location 8 in the

memory

Page 4: Controlled Assesment Little Man Computer

Start

Input first value

Store value and declare as variable

called DEC

Input second value

Set variable called LOOP and subtract

from DEC

Output

Is the number zero?

No

Page 5: Controlled Assesment Little Man Computer

Question 3) i) Entering the first input as 2 and the second input of 10. When it reaches the loop it will subtract the second input (the number in the accumulator which in this case is 10) from the first input (in this case is 2) and will keep subtracting the first input from the second each time as it is in the loop (10 – 2 = 8, 8 – 2 = 6, 6 – 2 = 4, 4 – 2 = 2, 2 – 2 = 0.) As it reaches 0 the program stops as Line 5 “BRZ QUIT” which means that if it equals 0 it will stop.

First Input Second Input Output What happens?

2 10 8 10-2, 8-2, 6-2 etc until it reaches 0 [Loop]

2 8 6 8-2. 6-2, 4-2 etc until it reaches 0 [Loop]

2 6 4 6-2, 4-2, 2-2 etc until it reaches 0 [Loop]

2 4 2 4-2, 2-2 etc until it reaches 0 [Loop]

2 2 0 2-2 until it reaches 0 [Loop]

When it reaches zero the program will stop.

Question 3) ii) Entering the first input as 3 and second input of 10. When it reaches the loop you find a flaw/problem in the program written. This is because the loop carries on repeatedly in the negative numbers and never ends because the program is written to stop at 0. Meaning because it got below 0 it will never stop as is doesn’t know when to stop. To prove this 10 – 3 = 7, 7 – 3 = 4, 4 – 3 = 1, 1 – 3 = -1… etc.

First Input Second Input Output What happens?

3 10 7 10-7, 7-3, 4-3 etc. [Endless Loop]

Yes

Program will stop

Page 6: Controlled Assesment Little Man Computer

3 7 4 7-3, 4-3, 1-3 etc [Endless Loop]

3 4 1 4-3, 1-3etc [Endless Loop]

3 1 -2 1-3 etc [Endless Loop]

3 -2 -5 -2-3 [Endless Loop]

Question 3) iii) Rewritten program to overcome the problem:

Line number Code Explanation0 INP Asks user for an input1 STA DEC Stores the input as a

variable called DEC2 INP Asks the user for another

input3 LOOP SUB DEC Subtract the second Input

from DEC and set variable LOOP

4 OUT Output the number

5 BRZ QUIT If the number is zero declare the variable QUIT

6 BRP LOOP If the number is positive go back to LOOP

7 BRA QUIT Branch always the variable QUIT

8 QUIT HLT Stop QUIT9 DEC DAT Store the variable DEC in

data location 9 in the memory

Input 1 Input 2 Output What happens

3 10 7 10-7

3 7 4 7-3

3 4 1 4-3

Page 7: Controlled Assesment Little Man Computer

3 1 -2 1-3

The number is not positive or zero, therefore stops the program at -2 stopping the endless loop and will with all inputs entered.

Page 8: Controlled Assesment Little Man Computer

Question 4) i)0. INP1. STA FIRST2. INP3. STA SECOND4. SUB FIRST5. BRP SECONDBIG6. LDA FIRST7. STA VALUE1

Page 9: Controlled Assesment Little Man Computer

8. OUT 9. LDA SECOND 10. STA VALUE211. BRA LOOPTOP12. SECONDBIG LDA SECOND13. STA VALUE114. OUT LDA SECOND 15. STA VALUE216. BRA LOOPTOP17. SECONDBIG LDA SECOND18. STA VALUE119. OUT20. LDA FIRST21. STA VALUE222. BRA LOOPTOP23. LOOPTOP LDA COUNT24. ADD ONE25. STA COUNT26. LDA VALUE127. SUB VALUE228. STA VALUE129. BRP LOOPTOP30. LDA COUNT31. SUB ONE32. OUT 33. HLT34. VALUE1 DAT35. VALUE2 DAT36. ONE DAT 00137. COUNT DAT 00038. FIRST DAT 39. SECOND DAT

Page 10: Controlled Assesment Little Man Computer

Line Number Code Explanation0 INP Asks user for an input

1 STA FIRST Stores the input using FIRST DAT in data location 38 and declares it a variable called

FIRST2 INP Asks user for another input

3 STA SECOND Stores the input using SECOND DAT in data location 39 and declares it as a variable called

SECOND4 SUB FIRST Subtract the SECOND variable from the FIRST

5 BRP SECONDBIG If the number is positive branch it to a variable called SECONDBIG in line 12

6 LDA FIRST Load the variable called FIRST from data location 38 in the memory into the accumulator

7 STA VALUE1 Store the value of the accumulator as a variable called VALUE1 (bigger number) in data

location 34 in the memory8 OUT Output variable called VALUE1 to the outbox

9 LDA SECOND Load the variable called SECOND from data location 39 in the memory into the accumulator

10 STA VALUE2 Store the value of the accumulator as a variable called VALUE2 (smaller number) in data

location 35 in the memory11 BRA LOOPTOP Branch always to a variable called LOOPTOP in

line 23

12 SECONDBIG LDA SECOND

Variable called SECONDBIG load variable called SECOND from data location 39 in the

memory into the accumulator.13 STA VALUE1 Store the variable called VALUE1 (bigger

number) in data location 34 in the memory

14 OUT LDA SECOND Output the value of the accumulator and load the variable called SECOND from data location

39 in the memory into the accumulator15 STA VALUE2 Store the variable called VALUE2 (smaller

number) in data location 35 in the memory

16 BRA LOOPTOP Branch always the value of the accumulator to the variable called LOOPTOP in line 23

17 SECONDBIG LDA SECOND

Variable called SECONDBIG load the variable called SECOND to the accumulator

18 STA VALUE1 Store the variable called VALUE1 (bigger number) in data location 34 in the memory

Page 11: Controlled Assesment Little Man Computer

19 OUT Output value of accumulator to outbox

20 LDA FIRST Load the variable called FIRST from data location 38 in the memory into the accumulator

21 STA VALUE2 Store the variable called VALUE2 (smaller number) in data location 35 in the memory

22 BRA LOOPTOP Branch always to the variable called LOOPTOP in line 23

23 LOOPTOP LDA COUNT Variable called LOOPTOP and load the variable called COUNT into the accumulator

24 ADD ONE Add the variable called ONE to the accumulator

25 STA COUNT Store the variable called COUNT in data location 37 in the memory

26 LDA VALUE1 Load the variable called VALUE1 (bigger number) to the accumulator from data location

34 in the memory27 SUB VALUE2 Subtract VALUE2 (smaller number) from the

value of the accumulator

28 STA VALUE1 Store the variable called VALUE1 (bigger number) in data location 34 in the memory

29 BRP LOOPTOP Branch always to the variable called LOOPTOP in line 23

30 LDA COUNT Load the variable called COUNT into the accumulator from data location 37 in the

memory31 SUB ONE Subtract the variable called ONE from the value

of the accumulator

32 OUT Output value of accumulator to outbox

33 HLT Stop the program

34 VALUE1 DAT Store the variable labeled VALUE1 (bigger number) in data location 34 in the memory

35 VALUE2 DAT Store the variable labeled VALUE2 (smaller number) in data location 35 in the memory

36 ONE DAT 001 Store the variable labeled ONE in data location 36 in the memory and give it a value of 001.

37 COUNT DAT 000 Store the variable labeled COUNT in data location 37 in the memory and give it a value of

00038 FIRST DAT Store the variable labeled FIRST in data

location 38 in the memory

39 SECOND DAT Store the variable labeled SECOND in data location 39 in the memory

Page 12: Controlled Assesment Little Man Computer

Progress of working out the division code:

INP STA VALUE1INP STA VALUE2LOOP LDA COUNTADD ONESTA COUNTLDA VALUE1SUB VALUE2 STA VALUE1BRZ ZEROFOUNDBRP LOOPLDA COUNT OUTHLTZEROFOUND LDA COUNTOUTHLTBRA LOOPBRA ZEROFOUNDVALUE1 DATVALUE2 DATONE DAT 001COUNT DAT 000

INPSTA FIRSTINPSTA SECONDSUB FIRSTBRP SECONDBIGLDA FIRSTSTA VALUE1OUT LDA SECOND STA VALUE2BRA LOOPTOPSECONDBIG LDA SECONDSTA VALUE1OUT LDA SECOND STA VALUE2BRA LOOPTOPSECONDBIG LDA SECONDSTA VALUE1OUTLDA FIRSTSTA VALUE2BRA LOOPTOPLOOPTOP LDA COUNTADD ONESTA COUNTLDA VALUE1SUB VALUE2STA VALUE1BRP LOOPTOPLDA COUNTSUB ONEOUT HLTVALUE1 DATVALUE2 DATONE DAT 001COUNT DAT 000FIRST DAT SECOND DAT

For my first attempt of division I was able to work out how to divide any number by another. However I was unable to divide the biggest number from the smallest and my code did not sort it out from biggest to smallest.

This is the final program. I tested it and everything works properly and it organizes the bigger number and the smaller number and divides the bigger from the smaller number which is what the task asked for.

Page 13: Controlled Assesment Little Man Computer

Start

Input first value

First > second

Store as FIRST

FIRST changed to VALUE1 and

SECOND to VALUE2

Store as SECOND

Yes

Input second value

No

SECOND changed to VALUE1 and FIRST to VALUE2

Load counter and increment

in ones

Is it positive

?

Yes

Division Flowchart

No

Page 14: Controlled Assesment Little Man Computer

First Input Second Input Output Counter What happens?

2 10 10 0 10>2 sorts out the biggest number from the smallest.

10 2 8 1 10-2

8 2 6 2 8-2

6 2 4 3 6-2

4 2 2 4 4-2

2 2 0 5 [Result] 2-2

End Program

Load Counter Subtract one from the value output

Page 15: Controlled Assesment Little Man Computer

Question 4 ii)

Average:

LOOPTOP INPBRZ LOOPTOP2ADD RESULTSTA RESULTLDA COUNTADD ONESTA COUNTBRA LOOPTOPLOOPTOP2 LDA COUNT2ADD ONESTA COUNT2LDA RESULTSUB COUNTSTA RESULTBRP LOOPTOP2OUTLDA COUNT2OUTSUB ONEOUTHLTONE DAT 001RESULT DAT 000

Page 16: Controlled Assesment Little Man Computer

COUNT DAT 000COUNT2 DAT 000

Line Number Code Explanation0 LOOPTOP

INPAsks a user a input(s) and declare a variable called LOOPTOP

1 BRZ LOOPTOP2

If the input is zero, it stops the continuation to line 2 and sends it to LOOPTOP2 on line 8, (stops the input of numbers), if not carry on to line 2.

2 ADD RESULT

Add the numbers inputted from line 0 to create a sum, and declare it as a variable called RESULT

3 STA RESULT

Store the variable RESULT in data location 22 in the memory. Shown on line 22

4 LDA COUNT

Load the variable called COUNT from data location 23 in the memory into the accumulator

5 ADD ONE Add the variable called ONE to the value of the accumulator

6 STA COUNT

Store the variable COUNT in data location 23 in the memory

7 BRA LOOPTOP

Branch always to the variable LOOPTOP in line 0

8 LOOPTOP2 LDA COUNT2

Variable called LOOPTOP2 and load the variable called COUNT2 into the accumulator

9 ADD ONE Add the variable called ONE onto the value of the accumulator

10 STA COUNT2

Store the value of the accumulator which is the variable called COUNT2 in data location 24 in the memory

11 LDA RESULT

Load the variable called RESULT into the accumulator from data location 22 in the memory.

12 SUB COUNT

Subtract the variable called COUNT from the value of the accumulator

Page 17: Controlled Assesment Little Man Computer

13 STA RESULT

Store the variable called RESULT in data location 22 in the memory

14 BRP LOOPTOP2

Branch if positive to the variable called LOOPTOP2 in line 8

15 OUT Output value of accumulator to outbox

16 LDA COUNT2

Load the variable called COUNT2 into the accumulator from data location 24 in the memory

17 OUT Output value of accumulator to outbox

18 SUB ONE Subtract the variable called ONE from the value of the accumulator

19 OUT Output value of accumulator to outbox

20 HLT Stop program

21 ONE DAT 001

Store the variable labeled ONE in data location 21 in the memory and give it a value of 1.

22 RESULT DAT 000

Store the variable labeled RESULT in data location 22 in the memory

23 COUNT DAT 000

Store the variable labeled COUNT in data location 23 in the memory

24 COUNT2 DAT 000

Store the variable labeled COUNT2 in data location 24 in the memory

First Input value

Is it zero? Yes

No

Load counter2 and increment

in ones and save

Load RESULT

RESULT – counter and store result

Is it positive

?

No

Load counter2 subtract one and output

Stop programYes

Add inputs declare as variable called

RESULT and store RESULT

Load counter and increment in one’s

and store.

Average Flowchart

Page 18: Controlled Assesment Little Man Computer
Page 19: Controlled Assesment Little Man Computer

Progression of average code:

LOOPTOP ADD RESULTSTA RESULTSTA RESULT2LDA COUNTADD ONESTA COUNTINPBRZ LOOPTOP2BRA LOOPTOPLOOPTOP2 LDA COUNT2ADD ONESTA COUNT2LDA RESULTSUB COUNTSTA RESULTBRP LOOPTOP2LDA RESULT2OUTLDA COUNT2OUTHLTONE DAT 001RESULT DAT 000COUNT DAT 000COUNT2 DAT 000RESULT2 DAT 000

LOOPTOP INPBRZ LOOPTOP2ADD RESULTSTA RESULTLDA COUNTADD ONESTA COUNTBRA LOOPTOPLOOPTOP2 LDA COUNT2ADD ONESTA COUNT2LDA RESULTSUB COUNTSTA RESULTBRP LOOPTOP2OUTLDA COUNT2OUTSUB ONEOUTHLTONE DAT 001RESULT DAT 000COUNT DAT 000COUNT2 DAT 000

This program did not work as it added zero as a number when inputting various values. For example when I entered the inputs 5, 10 and 0 it counted zero as a number and did not stop the process and move on to finding the average.

Working version and is the final program. It does not include zero when inputting various values. Instead when zero was entered it would stop the process and find the average of the values that were inputted.

Page 20: Controlled Assesment Little Man Computer

Question 5)

Evaluation of solutions:

Evaluation for question 3 iii: The original problem with the program given was that if the two values were not factors the program would enter an endless loop. However I came up with a solution that allowed the user to enter the two values and they didn’t have to be factors. When I changed the code slightly instead of entering an endless loop in the negatives it ended the program when it reached zero OR a negative number therefore preventing an endless loop.

Evaluation for question 4 i (Division): When I first looked at the task I decided to plan a few solutions to work out the code by writing on a piece of paper and after tested it on the little man computer. After testing out the division code I had I found out that there was a flaw with the code, the problem was that it did not organize the largest number from the smallest number. The task was to divide the larger value from the smallest value and after a few alterations I fixed my original code and got it to work. Therefore the user wouldn’t have to worry which way round to input a number for the code to work.

Evaluation for question 4 ii (Average): Again when I first looked at the task I decided to plan a few solutions to work out the code by writing on a piece of paper and after tested it on the little man computer. Yet again after testing my possible codes on the little man computer I again found a few flaws. The problem was that when I entered values it counted zero as a value when it was suppose to stop the process and find the average of the previous values entered. However after altering the code there was a few more flaws but for the same reason. After a while I found the solution that allowed me to make 0 stop the process and find the average of the pervious values entered. This now made the user enter as many values as they wanted and when they used the value 0 it would find the average and output the answer.

Page 21: Controlled Assesment Little Man Computer

Question 6)

There are lots of different assembly language; one for every processor architecture. The code is written in mnemonics, abbreviated text commands such as LOAD, STORE, ADD which we used when programming using the little man computer and has been used in my programs above. Along with assembly language comes a software application called an ‘Assembler’. This converts the assembly instructions back into machine code. Assembly language is an example for low level language. Assembly language is used for applications such as low-level device drivers. It is also used extensively in CPUs that specialize in control as you may find in a washing machine or DVD player.