Assembly Language Flashcards
Machine language
○ bit patterns that are directly executable by computer
○ May look like gibberish to humans but it is actually the binary encoded instructions that the CPU can understand.
○ May also contain data in addition to instructions.
○ Assembled into files called objects, binaries, executables, which specify how the machine memory should be set up
Assembly language
○ symbolic representation of machine language
○ Instructions as mnemonic ASCII strings e.g. ADD R2, R6, R2
○ Cannot run but mostly readable by humans
○ Can be handwritten or produced by a compiler from a high level language (like C)
○ Assembly files can also contain ASCII labels e.g. BRnzp LOOP
○ ISA dependent. (High level languages usually ISA independent). Usually the case that each ISA has only one assembly language
Assembler
used to translate assembly programs (.ASM) into machine code (.OBJ)
object file that is a specification for how the machine memory should be set up.
Linking
process of connecting several .OBJ files together into one executable program
Programming:
process of designing/writing/testing/debugging/maintaining the “source code” of computer programs
Conditional control
a way for our program to change the natural flow of a program based on a condition
Subroutine
group of instructions meant to perform a specific task e.g. square a number, print out a string, etc. in assembly; similar to a “function” in a high level language
Pointers
variable storing a memory address (as opposed to a regular variable that holds data)
Dereferencing
act of using the memory address held onto by a
pointer to read/write from the memory location held onto by that pointer
Assembly directives
provide an indication to the assembler of where it should place various blocks of code or data
How does assembler program operate
2 Phases:
First Phase: convert labels into offsets and remove comments
Second Phase: Converts assembly code into machine code. Uses ISA to do this and saves it in .obj file
After assembler finishes, a loader program load it into computer memory
Partitioning of LC4 Memory
User Region: - Programs run by user as excel Processes run in user Mode (PSR[15]=0) are not allowed to access OS location in memory - User Code: x0000 - x1FFF - User Data: x2000 - x7FFF
OS region:
- Processes run in OS mode with PSR[15]=1
- OS Code: x8000 - x9FFF. However, 1st address in OS is at x8200. Bw. x8000-x8200 -> TRAP Table
- OS Data + Device Memory: xA000 - xFFFF
.DATA
Next values are in data memory
.ADDR
Set current address to the specified value
.FILL IMM16
Set value at the current address to the specified 16-bit value
Loader Program
The object file specifies initial values for data memory locations. The loader program in the simulator takes this object file and configures the LC-4 memory according to these specifications.
Assembly Directives
.Data, .Code, . ADDR, . FILL IMM16
provide an indication to the assembler of where it should place various blocks of code or data
are NOT INSTRUCTIONS
Assembly files are stored in which format
Stored as text files. Text files consist of ASCII characters only
Code for small OS
.CODE .ADDR x8200 .FALIGN CONST R7, #0 RTI -> downgrade to user mode and set PC =R7
Advantage of Immediate addressing Mode instructions
Can bypass storing data first in register and specifying register address in instruction and instead can directly add data to instruction
TRAP
Changes the PC to a memory address that is part of the OS. So that the OS will perform some task in behalf of the program that is being run. ‘Service Call’.
Once OS is finished performing service call, the PC is set to the address of the instruction one after the TRAP call
Difference BRnzp vs. JMP
JMP has a wider range than using BRnzp to Jump
Outline for enabling, calling and returning from subroutine
- Give subroutine a unique name using a Label
- Ensure subroutine is loaded at memory address that is multiple of 16 -> .FALIGN
- Pass in argument using register file
- Call subroutine using JSR
- Return data using register file
- Return from subroutine using RET.
–> wrap subroutine into JMP so that it is not run by accident
Pointer
Address variable. Variable holding memory address