Sunteți pe pagina 1din 18

LMC Controlled Assessment

Contents
Contents....................................................................................................................................1 Question 1:................................................................................................................................2 Question 2:.......................................................................................................................3 Question 4) i)....................................................................................................................8 Question 4 ii)..................................................................................................................13 Question 5).....................................................................................................................17 Question 6).....................................................................................................................18

Question 1:

Variable DECs location

Shows the program has been successfully compiled

User enters input Provides user with an output

Question 2:

Line number
0 1 2 3

Code
INP STA DEC INP LOOP SUB DEC OUT BRZ QUIT BRA LOOP QUIT HLT DEC DAT

Explanation
Asks the user for an input Stores the input and declares it as a variable called DEC Asks the user for a second input Sets the variable LOOP, loads the variable called DEC to the accumulator and subtract the variable DEC from the second input Gives the user the output If the number is zero, set as the variable QUIT If the number is not zero, set variable LOOP Stop QUIT if reached zero and stop process Store DEC in data location 8 in the memory

4 5 6 7 8

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

Yes
Program will stop
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 2 2 2 2 2

Second Input 10 8 6 4 2

Output 8 6 4 2 0

What happens? 10-2, 8-2, 6-2 etc until it reaches 0 [Loop] 8-2. 6-2, 4-2 etc until it reaches 0 [Loop] 6-2, 4-2, 2-2 etc until it reaches 0 [Loop] 4-2, 2-2 etc until it reaches 0 [Loop] 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 doesnt know when to stop. To prove this 10 3 = 7, 7 3 = 4, 4 3 = 1, 1 3 = -1 etc.
First Input 3 3 3 3 3 Second Input 10 7 4 1 -2 Output 7 4 1 -2 -5 What happens? 10-7, 7-3, 4-3 etc. [Endless Loop] 7-3, 4-3, 1-3 etc [Endless Loop] 4-3, 1-3etc [Endless Loop] 1-3 etc [Endless Loop] -2-3 [Endless Loop]

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


Line number 0 1 2 Code INP STA DEC INP Explanation Asks user for an input Stores the input as a variable called DEC Asks the user for another

3 4 5 6 7 8 9

LOOP SUB DEC OUT BRZ QUIT BRP LOOP BRA QUIT QUIT HLT DEC DAT

input Subtract the second Input from DEC and set variable LOOP Output the number If the number is zero declare the variable QUIT If the number is positive go back to LOOP Branch always the variable QUIT Stop QUIT Store the variable DEC in data location 9 in the memory

Input 1 3 3 3 3

Input 2 10 7 4 1

Output 7 4 1 -2

What happens 10-7 7-3 4-3 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.

Question 4) i)
0. INP 1. STA FIRST 2. INP 3. STA SECOND 4. SUB FIRST 5. BRP SECONDBIG 6. LDA FIRST 7. STA VALUE1 8. OUT 9. LDA SECOND 10. STA VALUE2 11. BRA LOOPTOP 12. SECONDBIG LDA SECOND 13. STA VALUE1 14. OUT LDA SECOND 15. STA VALUE2 16. BRA LOOPTOP 17. SECONDBIG LDA SECOND 18. STA VALUE1 19. OUT 20. LDA FIRST 21. STA VALUE2 22. BRA LOOPTOP 23. LOOPTOP LDA COUNT 24. ADD ONE 25. STA COUNT 26. LDA VALUE1 27. SUB VALUE2 28. STA VALUE1 29. BRP LOOPTOP 30. LDA COUNT 31. SUB ONE 32. OUT 33. HLT 34. VALUE1 DAT 35. VALUE2 DAT 36. ONE DAT 001 37. COUNT DAT 000 38. FIRST DAT 39. SECOND DAT

Line Number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

Code INP STA FIRST INP STA SECOND SUB FIRST BRP SECONDBIG LDA FIRST STA VALUE1 OUT LDA SECOND STA VALUE2 BRA LOOPTOP SECONDBIG LDA SECOND STA VALUE1 OUT LDA SECOND STA VALUE2 BRA LOOPTOP SECONDBIG LDA SECOND STA VALUE1 OUT LDA FIRST STA VALUE2 BRA LOOPTOP LOOPTOP LDA COUNT ADD ONE

Explanation Asks user for an input Stores the input using FIRST DAT in data location 38 and declares it a variable called FIRST Asks user for another input Stores the input using SECOND DAT in data location 39 and declares it as a variable called SECOND Subtract the SECOND variable from the FIRST If the number is positive branch it to a variable called SECONDBIG in line 12 Load the variable called FIRST from data location 38 in the memory into the accumulator Store the value of the accumulator as a variable called VALUE1 (bigger number) in data location 34 in the memory Output variable called VALUE1 to the outbox Load the variable called SECOND from data location 39 in the memory into the accumulator Store the value of the accumulator as a variable called VALUE2 (smaller number) in data location 35 in the memory Branch always to a variable called LOOPTOP in line 23 Variable called SECONDBIG load variable called SECOND from data location 39 in the memory into the accumulator. Store the variable called VALUE1 (bigger number) in data location 34 in the memory Output the value of the accumulator and load the variable called SECOND from data location 39 in the memory into the accumulator Store the variable called VALUE2 (smaller number) in data location 35 in the memory Branch always the value of the accumulator to the variable called LOOPTOP in line 23 Variable called SECONDBIG load the variable called SECOND to the accumulator Store the variable called VALUE1 (bigger number) in data location 34 in the memory Output value of accumulator to outbox Load the variable called FIRST from data location 38 in the memory into the accumulator Store the variable called VALUE2 (smaller number) in data location 35 in the memory Branch always to the variable called LOOPTOP in line 23 Variable called LOOPTOP and load the variable called COUNT into the accumulator Add the variable called ONE to the accumulator

Progress of working out the division code:

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.

INP STA VALUE1 INP STA VALUE2 LOOP LDA COUNT ADD ONE STA COUNT LDA VALUE1 SUB VALUE2 STA VALUE1 BRZ ZEROFOUND BRP LOOP LDA COUNT OUT HLT ZEROFOUND LDA COUNT OUT HLT BRA LOOP BRA ZEROFOUND VALUE1 DAT VALUE2 DAT ONE DAT 001 COUNT DAT 000

INP STA FIRST INP STA SECOND SUB FIRST BRP SECONDBIG LDA FIRST STA VALUE1 OUT LDA SECOND STA VALUE2 BRA LOOPTOP SECONDBIG LDA SECOND STA VALUE1 OUT LDA SECOND STA VALUE2 BRA LOOPTOP SECONDBIG LDA SECOND STA VALUE1 OUT LDA FIRST STA VALUE2 BRA LOOPTOP LOOPTOP LDA COUNT ADD ONE STA COUNT LDA VALUE1 SUB VALUE2 STA VALUE1 BRP LOOPTOP LDA COUNT SUB ONE OUT HLT VALUE1 DAT VALUE2 DAT ONE DAT 001 COUNT DAT 000 FIRST DAT SECOND DAT

Start

Input first value

Division Flowchart
Store as FIRST

Input second value

Store as SECOND

First > second

Yes

FIRST changed to VALUE1 and SECOND to VALUE2

Yes

No

Load counter and increment in ones

Is it positive ?

SECOND changed to VALUE1 and FIRST to VALUE2

No

Load Counter Subtract one from the value output

End Program

First Input 2 10 8 6 4 2

Second Input 10 2 2 2 2 2

Output 10 8 6 4 2 0

Counter 0 1 2 3 4 5 [Result]

What happens? 10>2 sorts out the biggest number from the smallest. 10-2 8-2 6-2 4-2 2-2

Question 4 ii)
Average:
LOOPTOP INP BRZ LOOPTOP2 ADD RESULT STA RESULT LDA COUNT ADD ONE STA COUNT BRA LOOPTOP LOOPTOP2 LDA COUNT2 ADD ONE STA COUNT2 LDA RESULT SUB COUNT STA RESULT BRP LOOPTOP2 OUT LDA COUNT2 OUT SUB ONE OUT HLT ONE DAT 001 RESULT DAT 000 COUNT DAT 000 COUNT2 DAT 000

Line Number 0

Code LOOPTOP INP

Explanation Asks a user a input(s) and declare a variable called LOOPTOP

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

BRZ LOOPTOP2 ADD RESULT STA RESULT LDA COUNT ADD ONE STA COUNT BRA LOOPTOP LOOPTOP2 LDA COUNT2 ADD ONE STA COUNT2 LDA RESULT SUB COUNT STA RESULT BRP LOOPTOP2 OUT LDA COUNT2 OUT SUB ONE OUT HLT ONE DAT 001 RESULT DAT 000

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. Add the numbers inputted from line 0 to create a sum, and declare it as a variable called RESULT Store the variable RESULT in data location 22 in the memory. Shown on line 22 Load the variable called COUNT from data location 23 in the memory into the accumulator Add the variable called ONE to the value of the accumulator Store the variable COUNT in data location 23 in the memory Branch always to the variable LOOPTOP in line 0 Variable called LOOPTOP2 and load the variable called COUNT2 into the accumulator Add the variable called ONE onto the value of the accumulator Store the value of the accumulator which is the variable called COUNT2 in data location 24 in the memory Load the variable called RESULT into the accumulator from data location 22 in the memory. Subtract the variable called COUNT from the value of the accumulator Store the variable called RESULT in data location 22 in the memory Branch if positive to the variable called LOOPTOP2 in line 8 Output value of accumulator to outbox Load the variable called COUNT2 into the accumulator from data location 24 in the memory Output value of accumulator to outbox Subtract the variable called ONE from the value of the accumulator Output value of accumulator to outbox Stop program Store the variable labeled ONE in data location 21 in the memory and give it a value of 1. Store the variable labeled RESULT in data location 22 in the memory

23 24

COUNT DAT 000 COUNT2 DAT 000

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

First Input value

Average Flowchart

Is it zero?

Yes

No

Load counter2 and increment in ones and save

Load RESULT

Add inputs declare as variable called RESULT and store RESULT

RESULT counter and store result

Load counter and increment in ones and store. Yes Is it positive ? No

Load counter2 subtract one and output

Stop program

Progression of average code: 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.

LOOPTOP ADD RESULT STA RESULT STA RESULT2 LDA COUNT ADD ONE STA COUNT INP BRZ LOOPTOP2 BRA LOOPTOP LOOPTOP2 LDA COUNT2 ADD ONE STA COUNT2 LDA RESULT SUB COUNT STA RESULT BRP LOOPTOP2 LDA RESULT2 OUT LDA COUNT2 OUT HLT ONE DAT 001 RESULT DAT 000 COUNT DAT 000 COUNT2 DAT 000 RESULT2 DAT 000

LOOPTOP INP BRZ LOOPTOP2 ADD RESULT STA RESULT LDA COUNT ADD ONE STA COUNT BRA LOOPTOP LOOPTOP2 LDA COUNT2 ADD ONE STA COUNT2 LDA RESULT SUB COUNT STA RESULT BRP LOOPTOP2 OUT LDA COUNT2 OUT SUB ONE OUT HLT ONE DAT 001 RESULT DAT 000 COUNT DAT 000 COUNT2 DAT 000

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 didnt 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 wouldnt 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.

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.

S-ar putea să vă placă și