Briefly describe the advantages of using assembly language.
Symbolic names - opposed to binary code or numeric addresses
error detection - syntax errors, invalid addressing modes
hardware optimization - can be tailors for hardware features
What are two main functions of an assembler
a program that converts assembly language programs to object code
allows programmers to use symbolic names
What is a high-level language
what are the advantages of using one for programming? (2 advantages)
progamming language for human programmers
{
makes code portible
- not tied to a particular processor / instruction set/ architecture
abstracts away from the machine level details
- programmer does not need to know the processor hardware/ architecture/ components
problem oriented
- focus on program logic
}
Briefly describe the functions of a compiler.
processes HLL program code and generates assembler code for the target processor
Show with the aid of diagrams how conditional branches and unconditional jump statements are used to implement the following high-level programming constructs:
a. IF .. THEN .. ELSE conditional statement
b. WHILE loop
c. DO .. WHILE loop
(lol refer to slides i cant import images this shit ass, i remember that images used to be free)
short explanation tho:
JNZ (jump not zero) instruction would run and if there condition is True, then branch executed
conditional branch: when certain conditions are met
unconditional jump: executing code at another memory address.
Briefly explain (with the aid of diagrams) how data is stored and retrieved from a stack, including the role of the SP register.
image a stack of plates but you cannot take from the middle or bottom of the stack.
pushing:
* 3 words stored onto the stack:
Word A
then B
finally Word C
* Initially SP = address 0164h
* When Word A pushed:
SP automatically decremented to point to 0162h
Then Word A stored (little endian)
* Then Word B
* After Word C pushed:
SP will contain the address 015Eh
the new “top” of the stack
* Reverse process happens when ‘popping off’
data from stack.
popping:
* Reverse process happens when ‘popping off’
data from stack.
* E.g POP AX
* Top of stack data copied to register AX
* Then SP automatically incremented to point to 0160h
* the new “top” of the stack
Explain the role of CALL and RETURN instruction when implementing subroutines and the role of the stack in the execution of these instructions.
a subroutine is is a sequence of instructions that perform a specific task (like a python function)
CALL:
- address after the next instruction (after call) is pushed onto stack
- so the CPU knows where to come back to after finishing the subroutine
RETURN:
- pops the address from the stack
List the advantages of using subroutines when writing programs.
Allows for efficient and logical coding:
- Commonly used functions can be embedded insubroutines and called repeatedly as needed
- Do need to repeat the code for a function over and over in the main program
- less errors
Allows for previously developed code to be used (removes redundancy)
- library functions e.g. <cmath></cmath>
Allows code written in a different platform / language to be linked
- provided interface/ parameter passing is correct
Describe the function of a linker.
A linker is a program that combines various object files into a single executable file
◦ A program may call many subroutines that sit in various libraries
◦ The linker pulls in the required (called) library functions and creates a single executable (machine code) file that has all the required code.