Assembly Language Flashcards
What is assembly language?
A low-level programming language that uses mnemonic instructions specific to the processor’s architecture. It is not portable like high-level languages.
What are the two types of instruction sets in assembly language?
RISC (Reduced Instruction Set Computer): Simple instructions, single clock cycle execution, low energy consumption.
CISC (Complex Instruction Set Computer): Complex instructions, multiple clock cycles, higher efficiency with fewer lines of code.
What is immediate addressing?
The operand is a hardcoded value in the instruction (e.g., ADD #7 adds 7 to the accumulator). It is the fastest method since it doesn’t involve memory access.
What is direct addressing?
The operand specifies a memory location directly (e.g., ADD 7 adds the value at memory address 7). Requires fetching data from memory.
What is indirect addressing?
The operand refers to an intermediate memory location that holds the address of the actual data. Not part of the specification.
What are opcodes and operands?
Opcode: Specifies the operation to perform (e.g., ADD, MOV).
Operand: Specifies the data or memory location involved in the operation.
What does a typical instruction look like?
Instruction = Opcode + Operand
Example: LDR R1, #5 loads the value 5 into register R1.
What are some common assembly instructions in the AQA set?
LDR Rd, <memory>: Load value from memory to register.
STR Rd, <memory>: Store value from register to memory.
ADD Rd, Rn, <operand2>: Add operand2 to value in Rn, store in Rd.
SUB Rd, Rn, <operand2>: Subtract operand2 from value in Rn, store in Rd.
B <label>: Branch to the instruction at label.
HALT: Stop program execution.</label></operand2></operand2></memory></memory>
How do you perform addition in assembly?
Input two numbers into registers.
Use the ADD instruction to add them.
Output the result and halt.
Example:
INP R0
INP R1
ADD R2, R0, R1
OUT R2
HALT
How is multiplication performed without a MUL instruction?
Repeated addition. Add the first operand to itself as many times as specified by the second operand using a loop.
How is division performed without a DIV instruction?
Repeated subtraction. Subtract the divisor from the dividend until the result is 0 or negative. The number of subtractions equals the quotient.
How does assembly handle conditional branching?
By comparing values using CMP and branching based on the result (e.g., BEQ for equal, BGT for greater than).
How do you implement a loop in assembly?
Use a branch instruction to jump back to the loop start until a condition is met.
Example: Countdown loop:
MOV R0, #10
LOOP: OUT R0
SUB R0, R0, #1
CMP R0, #0
BNE LOOP
HALT
How do you validate input in assembly?
Use a loop to repeatedly request input until it meets the condition. Example: Entering a number > 100.
How is a Fibonacci sequence implemented in assembly?
Use three registers to hold the last two numbers and their sum. Update the registers iteratively.