#Computer-Science#Computer-Architecture#CS250
- Assembly language is a human readable version of machine language
- Characteristics of Assembly
- One statement in assembly = one machine instruction
- Very few abstractions of hardware details
- Used when writing code to control hardware
- Assembly language is low level
- Software Hierarchy
Syntax of Assembly Language
- While each assembly language is different, they all look very similar
- Typical instruction syntax:
label: opcode result, operand1, operadn2; comment
- label is a symbolic (or abstraction) for the memory address pointing to the location storing this instruction
- labels are for programmers and are translated into bit strings by the assembler
- op is a mnemonic for the operation to perform
- eg ADD for integer addition, FADD for floating point addition
- result is the location string where the result should be placed
- operandX is a pointer or an immediate value to be used in the operation
- after a delimiter (; in this case) there is often a comment
Register names
- using registers is IMPORTANT
- register names in assembly language is symbolic rather than a 0-bit or longer bit string as they appear in machine langugae
- examples for register 10
- $10, R10, r10
Numbers
- Decimal numbers are used by default, 10 means ten
- May need a special symbol to denote, eg #10
- For hex we use 0x-----
Memory Pointer Syntax
- Denote a bit string or source of a bit string for use as a memory address
- Typical forms
ldr r2, (r1);
load a register, r2 here, with the bit string from memory at location pointed to by bit string in r1ldr r2,[r1];
same as above but brackets
Assembly languages will have a syntax for each operand type supported by the processor
- immediate
- reference to register
- reference to memory
Programming in Assembly
To program in assembly we need to know…
- The mathematical/logical definition of truth table for each operation
- Mnemonic for each operation
- Required additional opearnds
- The syntax to specify operands as immediate or by pointing
- Sequence operands have to be listed in
- When to use an dhow to direct the allocation and use of…
- registers
- data segments of a process
- stack segments of a process
Assembly is easy to write, but its so low level that it can be hard to see the big picture
- comments are essential
- Block comment - explain the purpose of and detail the register/memory use of a code section
- Line comments - explain the PURPOSE of one instruction
- Don’t just restate the instruction name with the same registers, actually explain what the instruction is doing and why you’re using it
- A good strategy is to have a block comment and comment most lines in every assembly program
- Example assembly program
Why write in Assembly?
- Assembly language…
- Is tightly coupled to the processor, therefore not portable
- Does little per line of code, expect a lot of lines
- Brings memory addressing and register management to the fore front, which a HLL would do automatically
- Why would we make ourselves use this?
- Write more efficient (smaller, faster) code
- Write the core of an operating system
- Write the compiler for a new HLL
- Speed up AI, ML, and GPU computations
- Look for security vulnerabilities in systems
- To interface with input/output devices
- Find Easter eggs and uncover unannounced future technology directions