A Level · 1.2.4
Types of Programming Language and Assembly
Name
Class
Date
Mark / 30
Section A
Circle the letter of the correct answer. One mark each.
- 1What does immediate addressing mean?1
- AThe operand points to an address holding the address
- BThe operand is the value itself
- CThe operand is added to an index register
- DThe operand is the address of the value
- 2Which addressing mode is most useful for stepping through an array?1
- AIndexed
- BImmediate
- CDirect
- DAbsolute
- 3In LMC, what does BRP do?1
- ABranches if the accumulator is zero
- BPrints the accumulator
- CBranches always
- DBranches if the accumulator is zero or positive
- 4Which paradigm bundles data with the methods that operate on it?1
- AObject oriented
- BAssembly
- CDeclarative
- DProcedural
- 5Which is an advantage of the procedural paradigm for a short data processing script?1
- AIt guarantees data validity
- BIt supports polymorphism
- CIt provides inheritance
- DIt is simple and direct, with none of the overhead of defining classes
- 6What does indirect addressing allow?1
- AArray traversal only
- BValues fixed at compile time
- CThe use of pointers and dynamic data structures
- DFaster access than immediate addressing
- 7Why is assembly language still used for device drivers?1
- AIt gives direct control over hardware registers with predictable timing
- BIt is portable across all processors
- CIt is easier to write than a high level language
- DIt requires no translator
- 8In LMC, what does
STA 42do?1- ALoads address 42 into the accumulator
- BStores the accumulator into address 42
- CAdds 42 to the accumulator
- DBranches to address 42
- 9Which is a disadvantage of the object oriented paradigm?1
- AIt cannot model real world entities
- BCode cannot be reused
- CIt adds complexity and overhead that is unnecessary for small programs
- DData cannot be protected
- 10SQL is an example of which paradigm?1
- AObject oriented
- BAssembly
- CProcedural
- DDeclarative
Section B
Answer in the space provided. The number of marks tells you how many separate points to make.
- 1ExplainExplain the difference between immediate and direct addressing.3
- 2ExplainExplain why indexed addressing is useful when working with arrays.3
- 3JustifyA company is developing a large system that will be maintained by a team over many years and will need new types of user account added regularly. Justify the use of the object oriented paradigm.6
- 4StateThe following Little Man Computer program is executed with inputs 7 and 3. State the output and explain how it is produced. INP, STA 90, INP, STA 91, LDA 90, SUB 91, OUT, HLT4
- 5ExplainExplain one situation in which assembly language would be preferred over a high level language, and one disadvantage of that choice.4
Mark scheme
Section A
Section B
1 Explain the difference between immediate and direct addressing. 3
One mark for each of the following, to a maximum of 3.
- In immediate addressing the operand is the value to be used
- In direct addressing the operand is the address where the value is stored
- Immediate needs no memory access so is faster, but the value is fixed
Model answer. In immediate addressing the operand contained in the instruction is the actual value to be operated on, so an instruction to add five carries the number five within it. In direct addressing the operand is instead a memory address, and the value to be used is whatever is currently stored at that address, so the processor must perform a memory read before it can carry out the operation. Immediate addressing is therefore faster, since no memory access is required, but the value is fixed at the moment the program is written and cannot change while it runs, whereas direct addressing works with data that varies during execution.
2 Explain why indexed addressing is useful when working with arrays. 3
One mark for each of the following, to a maximum of 3.
- The address used is the operand plus the contents of an index register
- The base address of the array stays fixed within the instruction
- Only the index register needs to change to move to the next element
Model answer. In indexed addressing the effective address is calculated by adding the operand in the instruction to the contents of a dedicated index register. This maps directly onto how an array works: the operand holds the base address of the array and the index register holds the position within it. To move from one element to the next, only the index register has to be incremented, and the same instruction can then be executed repeatedly inside a loop without any modification. This is far more efficient than the alternative of generating a different instruction for every element or performing separate arithmetic to calculate each address.
3 A company is developing a large system that will be maintained by a team over many years and will need new types of user account added regularly. Justify the use of the object oriented paradigm. 6
One mark for each of the following, to a maximum of 6.
- Recommends object oriented
- Encapsulation keeps data with the methods that act on it and protects its validity
- Inheritance places shared behaviour in a superclass so it is written once
- A new account type is added as a subclass without changing existing code
- Polymorphism lets existing code work with new types through the same interface
- These properties make a large system maintainable by a team over time
Model answer. The object oriented paradigm is the right choice here, principally because of how the system will change over its lifetime. Encapsulation bundles each account's data together with the methods that operate on it and restricts direct access from outside, which means the rules governing what a valid account looks like live in one place and are enforced automatically, rather than being scattered through the codebase where a single developer forgetting a check could corrupt the data. Inheritance addresses the requirement for regularly added account types directly: everything common to all accounts is written once in a base Account class, and each specific type becomes a subclass that inherits that behaviour and overrides only what differs. This eliminates duplication, so a correction to shared logic is made in one place and applies everywhere. Polymorphism then means that existing code which processes accounts continues to work unchanged when a new subclass appears, because it calls the same methods and each object supplies its own implementation. Adding a new account type therefore involves writing one new class rather than finding and editing every conditional statement in the system, which is exactly what a procedural design would require. Over a system maintained by a team for many years, these properties are what keep the cost of change roughly constant instead of rising steeply as the codebase grows.
4 The following Little Man Computer program is executed with inputs 7 and 3. State the output and explain how it is produced. INP, STA 90, INP, STA 91, LDA 90, SUB 91, OUT, HLT 4
One mark for each of the following, to a maximum of 4.
- The first input 7 is stored at address 90
- The second input 3 is stored at address 91
- The accumulator is loaded with 7 and 3 is subtracted
- The output is 4
Model answer. The first INP instruction places the value 7 into the accumulator, and STA 90 stores it at address 90. The second INP replaces the accumulator contents with 3, and STA 91 stores that at address 91. LDA 90 then loads the contents of address 90, which is 7, back into the accumulator, and SUB 91 subtracts the contents of address 91, which is 3, leaving 4 in the accumulator. OUT displays the accumulator, so the output is 4, and HLT stops the program.
5 Explain one situation in which assembly language would be preferred over a high level language, and one disadvantage of that choice. 4
One mark for each of the following, to a maximum of 4.
- Gives a valid situation such as a device driver or a tightly constrained embedded system
- Assembly gives direct control over registers, memory and timing
- Disadvantage: it is far harder to write, read and maintain
- Disadvantage: it is specific to one processor architecture so it is not portable
Model answer. Assembly language would be preferred when writing a device driver or the control software for an embedded system with severe constraints. In those situations the programmer needs direct control over specific hardware registers and memory locations, and needs to know exactly how many cycles a sequence of instructions will take, neither of which a high level language and its compiler can guarantee. Assembly also allows the code to be made extremely compact, which matters when the whole program must fit into a few kilobytes of ROM. The disadvantages are substantial. Assembly is far harder to write, read and maintain than a high level language, because a single statement in a high level language may correspond to a dozen assembly instructions with no self documenting structure, so development takes much longer and errors are both more likely and harder to find. It is also written against one specific processor's instruction set, so the code is not portable and moving to different hardware means rewriting it entirely rather than recompiling.