Computer Science AS OCR
-
1-1-structure-and-function-of-the-processor as5 主题
-
1-2-types-of-processor as3 主题
-
1-3-input-output-and-storage as2 主题
-
2-1-systems-software as8 主题
-
2-3-software-development as5 主题
-
2-4-types-of-programming-language as4 主题
-
3-1-compression-encryption-and-hashing as3 主题
-
3-2-databases as3 主题
-
3-3-networks as8 主题
-
3-4-web-technologies as13 主题
-
html as
-
css as
-
css-styling as
-
javascript as
-
variables-and-constants-in-javascript as
-
outputs-in-javascript as
-
selection-in-javascript- as
-
for-loops-in-javascript- as
-
while-loops-in-javascript- as
-
strings-in-javascript- as
-
operators-in-javascript- as
-
nested-statements-in-javascript as
-
functions-and-procedures-in-javascript as
-
html as
-
4-1-data-types as8 主题
-
4-2-data-structures as4 主题
-
4-3-boolean-algebra as1 主题
-
5-1-computing-related-legislation as4 主题
-
5-2-moral-and-ethical-issues as9 主题
-
6-1-thinking-abstractly as3 主题
-
6-2-thinking-ahead as1 主题
-
6-3-thinking-procedurally as3 主题
-
6-4-thinking-logically as2 主题
-
6-5-thinking-concurrently as2 主题
-
7-1-programming-techniques as9 主题
-
8-1-standard-algorithms-and-big-o-notation as8 主题
assembly-language-and-little-man-computer- as
Exam code:H046
Assembly Language & Little Man Computer
What is the purpose of assembly language?
-
Assembly language sits between high-level languages (like Python, Java) and machine code (binary code executed by the computer hardware)
-
Allows developers to write more efficient, albeit more complex, code when compared to high-level languages
-
Direct access and manipulation of hardware components, e.g., registers, memory addresses
-
Each type of computer CPU has its specific assembly language

Levels of Abstraction of Programming Languages
Little Man Computer
-
The Little Man Computer (LMC) is a hypothetical computer model used for understanding the fundamental operations and mechanics of a computer
-
The LMC is a simplified version of a computer
-
It has key elements like memory, a calculator, an accumulator, and an instruction set
Little Man Computer instruction set
-
The following mnemonics represent different actions that can take place in an LMC program
|
Mnemonic |
Instruction |
Alternative Mnemonic |
|---|---|---|
|
ADD |
Add |
|
|
SUB |
Subtract |
|
|
STA |
Store |
STO |
|
LDA |
Load |
LOAD |
|
BRA |
Branch always |
BR |
|
BRZ |
Branch if zero |
BZ |
|
BRP |
Branch if positive OR zero |
BP |
|
INP |
Input |
IN, INPUT |
|
OUT |
Output |
|
|
HLT |
End program |
COB, END |
|
DAT |
Data location |
|
Example 1: Add two numbers
INP; // Input the first number
STA 90; // Store the first number in memory location 90
INP; // Input the second number
ADD 90; // Add the number in memory location 90 to the accumulator
OUT; // Output the result
HLT; // End the program
DAT; // Memory location 90 for storing data
Example 2: Find the largest of three numbers
-
This program inputs three numbers and determines the largest of the three, outputting the result.
INP // Input the first number
STA 91 // Store the first number in memory location 91
INP // Input the second number
STA 92 // Store the second number in memory location 92
INP // Input the third number
STA 93 // Store the third number in memory location 93 LDA 91
SUB 92
BRP compare13 // If the first number is greater than or equal to the second, compare it to the third
LDA 92
SUB 93
BRP output2 // If the second number is greater than or equal to the third, output it
LDA 93
OUT
HLT compare13 LDA 91
SUB 93
BRP output1 // If the first number is greater than or equal to the third, output it
LDA 93
OUT
HLT output1 LDA 91
OUT
HLT output2 LDA 92
OUT
HLT DAT
DAT
DAT
How it works:
-
This worked example demonstrates branching logic and how comparisons are chained to identify the correct result using
SUBandBRP-
Inputs are stored in memory locations 91, 92, and 93
-
The program first checks if the first number ≥ second number
-
If so, it then checks the first vs third
-
If not, it checks if the second number ≥ third number
-
The value that is greatest is loaded into the accumulator and output
-
Worked Example
A digital thermostat has a CPU that uses the Little Man Computer Instruction Set.
The thermostat allows users to set a desired room temperature. The acceptable range for room temperature settings is between 15 and 25 degrees Celsius, inclusive. If the user sets a temperature within the range, the code outputs a 1 indicating a valid setting. If the temperature setting is outside of the acceptable range, the code outputs a 0 indicating an invalid setting.
The code is as follows:
INP
STA tempSetting LDA tempSetting
SUB minTemp
BRP checkMax // If tempSetting ≥ 15, check against max LDA invalidVal
BRA end checkMax LDA maxTemp
SUB tempSetting
BRP isValid // If maxTemp - tempSetting ≥ 0, input is valid LDA invalidVal
BRA end isValid LDA validVal end OUT
HLT validVal DAT 1
invalidVal DAT 0
minTemp DAT 15
maxTemp DAT 25
tempSetting DAT
a) What is the purpose of the label checkMax in the code? Describe its role in determining the validity of the temperature setting.
[2]
b) If a user inputs a temperature setting of 14, what will be the output? Justify your answer.
[2]
c) If the acceptable range of temperature settings was expanded to include temperatures up to 30 degrees Celsius, what modification would be needed in the code?
[2]
Answer:
Example answer that gets full marks:
a) The label checkMax marks the section of code that checks whether the temperature setting is less than or equal to the maximum allowed value (25).
It is used to continue validation only after confirming that the input is greater than or equal to the minimum temperature (15).
If the temperature is within range, the program continues from checkMax to determine if it is also below the maximum; otherwise, it skips this section.
b) The output will be 0.
This is because 14 is less than the minimum allowed value of 15.
The program compares the input to the minimum temperature first, and since 14 is below 15, it does not continue to checkMax and instead loads and outputs the invalid value (0).
c) The value stored at the maxTemp label should be changed from 25 to 30.
This allows the program to correctly validate temperatures up to and including 30 degrees when comparing the input against the maximum allowed temperature.
Acceptable answers you could have given instead:
a) Any response mentioning that checkMax it is for checking if the user’s input is below or equal to the maximum allowable temperature should be awarded marks.
b) Any answer stating that the output will be 0 because 14 is less than 15, or similar logic, should be awarded marks.
c) Any answer suggesting a change to the maxTemp DAT value to 30 should be awarded marks.
Responses