Direct manipulation of hardware

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Direct manipulation of hardware

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which type of language lets a programmer work directly with registers and memory locations?
A Low-level language
B High-level language
2. A programmer wants to choose exactly which memory location stores a value. Which is more suitable?
A Assembly language
B A high-level language such as Python
3. Which statement about high-level languages is correct?
A They give the programmer less direct control of the hardware
B They let the programmer choose which register holds each value
4. Which program is most likely to be written in a low-level language?
A A quiz game that stores scores in a list
B A device driver that talks to a printer
5. Why might an embedded system, such as a washing machine controller, use low-level code?
A It hides the hardware so the code is easier to write
B It can control the hardware directly and use little memory

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1LDA 200 AMOV AX, 5
2STA 305 BPython is a high-level language that hides registers, so it does not give this direct control. Assembly or another low-level language should be used.
3Low-level code lets the programmer choose which register holds a value CLoads the value stored at memory location 200 into the accumulator register
4High-level languages hide registers and memory addresses, giving less direct control DThis is the wrong way round. Low-level languages let the programmer work with memory locations directly, while high-level languages hide them.
5A programmer writes in Python to choose exactly which register stores a value in a device driver. Etotal = price + tax
6Low-level languages hide memory locations from the programmer so they never have to think about them. FStores the value in the accumulator register into memory location 305

Definitions

direct hardware control

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
___ 200 ; load from memory address 200
2.
LDA 200 ___ 300 ; copy accumulator to address 300
3.
MOV __, 5 ; put 5 into register 1
4.
LDA 200 ; load first number ___ 201 ; add second number STA 202 ; save result in memory
5.
IN ; read from the keyboard STA 200 ; store in memory ___ ; send to the display

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A LDM #5 // put 5 in ACC
B ADD #3 // add 3 to ACC
C STO #300 // to address 300
D END
Question 2
A LDD 500 // read sensor at 500
B ADD #501 // add value at 501
C STO 502 // save at 502
D END
Question 3
A IN // key into ACC
B STO 100 // store key at 100
C LDM 100 // load key from 100
D OUT // show the character
Question 4
A LDM #1 // 1 means ON
B STO 900 // heater port
C LDM #0 // 0 means OFF
D LDM 901 // fan port
E END
Question 5
A STO 250 // read counter
B ADD #1 // add 1
C STO 250 // write it back
D END

Answer Key

Direct manipulation of hardware
Section A: Quick Questions
Q1
A — Low-level language
Q2
A — Assembly language
Q3
A — They give the programmer less direct control of the hardware
Q4
B — A device driver that talks to a printer
Q5
B — It can control the hardware directly and use little memory
Section B: Match the Pairs
Q1
LDA 200 → Loads the value stored at memory location 200 into the accumulator register
Q2
STA 305 → Stores the value in the accumulator register into memory location 305
Q3
Low-level code lets the programmer choose which register holds a value → MOV AX, 5
Q4
High-level languages hide registers and memory addresses, giving less direct control → total = price + tax
Q5
A programmer writes in Python to choose exactly which register stores a value in a device driver. → Python is a high-level language that hides registers, so it does not give this direct control. Assembly or another low-level language should be used.
Q6
Low-level languages hide memory locations from the programmer so they never have to think about them. → This is the wrong way round. Low-level languages let the programmer work with memory locations directly, while high-level languages hide them.
Section C: Definitions
Q1
direct hardware control — Low-level code can work directly with hardware, such as registers and memory locations, which high-level languages usually hide from the programmer.
Section D: Fill in the Blanks
Q1
LDA 200 ; load from memory address 200
Q2
LDA 200 STA 300 ; copy accumulator to address 300
Q3
MOV R1, 5 ; put 5 into register 1
Q4
LDA 200 ; load first number ADD 201 ; add second number STA 202 ; save result in memory
Q5
IN ; read from the keyboard STA 200 ; store in memory OUT ; send to the display
Section E: Spot the Error
Q1
C — STO writes the ACC register to a memory address, so it needs the plain address 300. The # sign means a fixed number, which is not a memory location. It should be STO 300.
Q2
B — ADD #501 adds the number 501 itself. The comment says to add the value stored at address 501, so the line must use the address: ADD 501.
Q3
C — LDM loads the number 100 into the register. To load the key stored at memory address 100, the program needs LDD 100.
Q4
D — This line should write the 0 in ACC to the fan port at address 901 to switch the fan off. LDM only loads a value and does not write to memory. It should be STO 901.
Q5
A — The first line must read the counter from address 250 into the ACC register. STO does the opposite and writes ACC into memory. It should be LDD 250.