Assembly Flashcards

1
Q

What is an instruction set?

A

An instruction set is a series of commands typically written in machine code which a CPU is programmed to recognise and respond to. An instruction set can refer to all the instructions for a particular CPU or a subset.

-WhatIs.com

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Features of the MIPS Processor

A

The MIPS (Microprocessor without Interlocked Pipelined Stages) is a processor with 32 general registers.

It uses 32-bit instructions to form its instruction set.

32 bit represents a word in MIPS.

Notable for a small number of formats encoding opcodes

It uses a 32x32 bit register file for frequently accessed data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does MIPS stand for?

A

Microprocessor without Interlocked Pipelined Stages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How are instructions represented in an instruction set?

A

They are encoded in binary or machine code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How are instructions encoded in MIPS?

A

They are encoded as 32-bit instruction words.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What instruction formats are part of MIPS?

A

MIPS has three instruction formats,

The I Format: I for immediate

The J Format for Jump Instructions

The R Format for arithmetic or register-based instructions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define Register.

A

A register is a small amount of memory in the CPU, it is quickly accessible and used to primarily to perform arithmetic operations in the CPU, storing the results of operations, the numbers on which the calculation is performed with etc. Registers may also have specific functions where some registers cannot be written to and only read from.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the purposes of registers?

A

Registers are the fastest and primary form of memory in the computer. They are most often used to perform arithmetic operations as accessing main memory is far slower. Certain register s may have special functions such as the $zero register in MIPS which cannot be rewritten and is always zero.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How many general-purpose registers does the MIPS processor have?

A

32 general registers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a register operand?

A

An operand, in general, refers to the piece of an instruction that specifies what data can be manipulated. As such the term register operand in the context of MIPS means that registers act as operands and the data stored on them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the MIPS regsiter file?

A

A register file is an array of the processor registers on a CPU. MIPS uses a 32x32 bit register file.

It is numbered 0 to 31, with 32-bit words.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When is the MIPS register file used?

A

The register file is used for frequently accessed data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What register operand names are used for the assembler?

A

Assembler names include:

$s0 to $s7 for the saved variables

$t0 to $t7 for the temporary values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the MIPS design principle?

A

Smaller is faster, maximise design with millions of memory locations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the MIPS general registers?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is register r0?

A

r0 has the assembly name $zero. It represents 0 and is a read-only register.

It is always zero.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is register r30?

A

Register r30 has the assembly name $fp, it is the frame pointer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is register r31?

A

Register r31 has the assembly name $ra, it is the return address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is register r29?

A

Register r29 has the assembly name $sp, it is the stack pointer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is register r28?

A

Register r1 has the assembly name $gp, it is the global pointer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is register r1?

A

Register r1 has the assembly name $at, it is reserved for pseudoinstructions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are registers r4to r7?

A

These registers have the names $a0, $a1, etc.. They store arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are registers r2 to r3?

A

These registers have the names $v0, $v1. They store results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What are registers r26 to r27?

A

These registers have the names $k0, $k1.. They are reserved by the operating system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What are registers r23 to r25?

A

These registers have the names $t8, $t9.. They store temporary which are not saved

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What are registers r16 to r23?

A

These registers have the names $s0, $s1, etc.. They store values to be saved for future use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What are registers r8 to r15?

A

These registers have the names $t0, $t1, etc.. They store temporary values which are not saved.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Define assembly language

A

Assembly language is a programming tool designed to be closer to machine code. The instructions available in assembly are dependent on the machine’s instruction set.

It has an almost 1:1 mapping with machine code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Why was assembly used, and why is it used today?

A

Assembly was designed to make code a bit easy to understand in early systems, however, small resources meant that the instruction set had to be as efficient as possible.

Today, assembly is used each time a compiler is run, used in the inner core of operating systems and to optimise a system. It provides process control overtime cost. Suitable for low-level interactions such as a microcontroller, it helps with performance analysis as to allows observation of the compiler and where the program spending most of its time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is the format for Arithmetic Operations?

A

Arithmetic Operations use the R-Format, the instructions require three operands. Operands are a destination, and two sources:

add a, b, c # a = b+c

Here the design principle is simplicity favours regularity
• Regularity makes implementation simpler
• Simplicity enables higher performance at lower cost

31
Q

Registers Vs Memory

A

Registers are faster to use than memory, this is in part because using memory requires loads and stores. These are slow instructions.

As such compilers should use registers as much as possible, only enter memory for rarely used variables.

32
Q

What is the main memory mostly used for?

A

Used for composite data.

Arrays, structures, dynamic data.

33
Q

How are arithmetic operators applied to memory?

A
  1. Load values from memory into registers
  2. Store result from register to memory
34
Q

How is memory addressed?

A

Memory is byte addressed, i.e. 8-bits.

35
Q

Words in memory?

A

Words are aligned in memory,

this means an address must be a multiple of 4 for 32 bit words.

36
Q

Format for R-Type Instructions

A

Instruction fields

  • op: operation code (opcode) – for R-type instructions this is always zero
  • rs: first source register number
  • rt: second source register number
  • rd: destination register number
  • shamt: shift amount (only used in shift operations)
  • funct: function code (extends opcode) – defines what operation should be run.
37
Q

Format for I (Immediate)-Type Instruction

A

Immediate arithmetic and load, store instructions

  • op: this time, identifies the instruction
  • rt: destination or source register number
  • Constant: –215 to +215 – 1
  • Address: offset added to the base address in rs
38
Q

Features of Immediate Instructions

A

Constant data is specified in the instruction. As no subtraction immediate instruction, negative numbers are used for subtractions.

When designing immediate instructions, make the common case fast.

Small constants are common, and immediate operands avoid the load instruction.

39
Q

Format for Jump Instructions

A

Jump (j and jal) targets could be anywhere in the text segment

  • Encode full address in the instruction

(Pseudo)Direct jump addressing

  • Target address = PC31…28 : (address × 4)
40
Q

How do jump instructions work?

A

The jump instructions load a new value into the PC register, which stores the value of the instruction being executed. This causes the next instruction read from memory to be retrieved from a new location.

41
Q

How do shift operations work in MIPS?

A

Uses the shamt operand in R-type insructions to specify the number of positions to shift.

For shift left operations, shift left and fill with 0 bits, effectively multiplied by 2i where i the number of positions shifted.

For shift right operations, shift right and fill with 0 bits.

Divides by 2<strong>i </strong>unsigned only

42
Q

When should an AND operation be used?

A

Can be useful to mask bits, select some and erase the rest.

43
Q

Why use OR operations

A

Can be useful for including bits into a word.

44
Q

How to implement NOT operations.

A

MIPS doesn’t have a NOT instruction but does have a nor instruction. NOR = NOT(OR(a,b)))

As such to implement not, nor a word with zero.

45
Q

How are conditional instructions implemented?

A

There are three instructions used to implement conditional statements, the beq, bne.

The beq instruction compares two operands:

beq rs, rt, L1
if (rs == rt) branch to instruction labeled L1;

Then the program jumps to instruction L1.

The bne instruction works similarly except

if (rs != rt) branch to instruction labeled L1;

then unconditional jump.

46
Q

How are loops implemented in MIPS?

A

Loops are implemented using j instructions and the beq and bne instructions to end loops.

47
Q

What are the Addressing Modes?

A

There are 5 addressing modes, Immediate addressing, register addressing, base addressing, PC relative addressing and pseudo-direct addressing.

48
Q

Describe Immediate Addressing

A

The operand is a constant within the instruction

49
Q

Describe Register Addressing

A

Where the operand is a register.

50
Q

Describe Base/Displacement Addressing

A

Where the operand is at the memory location which is the sum of a register and a constant included in the instruction.

51
Q

Describe PC- Relative Addressing

A

Where the branch address is the sum of the PC and a constant in the instruction

52
Q

Describe Pseudo-direct Addressing

A

Where the jump address is the 26 bits in the instruction concatenated with the upper bits of the PC.

53
Q

What is the slt instruction?

A

The slt instruction is a conditional operator. It has three operands, the destination register, and 2 sources.

Example:

slt, rd, rs, rt # if rs < rt then rd = 1

Often used in conjunction with branch instructions, beq and bne.

54
Q

What is sign extension?

A

To increase the size of a data item by
replicating the high-order sign bit of the original data item in the high order bits of the larger, destination data item.

55
Q

Where is sign extension often used?

A

Sign extension is used in many applications, in essence whenever a constant is needs to be expanded to a 32-bit word. Most often used in addresses.

56
Q

Requirements for load byte and load halfword

A

lb rt, offset(rs); lh rt, offset(rs)
• Sign extend to 32 bits in rt

57
Q

Requirements for load byte unsigned and load halfword unsigned?

A

lbu rt, offset(rs) lhu rt, offset(rs)
• Zero extend to 32 bits in rt

58
Q

How does store byte and store halfword work?

A

sb rt, offset(rs) sh rt, offset(rs)
• Store just rightmost byte/halfword

59
Q

Why use lui instruction and how

A

Used to for constants greater than 16 bits.

For the occasional 32-bit constant
lui rt, constant
• Copies 16-bit constant to left 16 bits of rt
• Clears right 16 bits of rt to 0

60
Q

Whyt are there no blt, bge etc instructions?

A

This is because beq and bne are the most common cases, and the hardware is slower for less than comparisons compared to equality so beq and be are used.

61
Q

What are pseudo instructions?

A

Pseudoinstructions unlike most assembler instruction do not represent machine code in a one to one conversion.

They are more similar to macros, at assembly are substituted for real instructions.

62
Q

How is memory structured in MIPS?

A

Memory is divided into several sections. The lowest level is memory reserved by the OS. Above that is text memory, then static data, then above that is dynamic data and the stack.

63
Q

What is static data?

A

Static data are global variables, such as:

e.g., static variables in C, constant arrays
and strings
The global pointer is initialized to address allowing
±offsets into this segment

64
Q

What is dynamic data?

A

Dynamic data is the heap, where user-created memory is stored e.g. malloc in C, new in C++

65
Q

What is the stack, how is it used?

A

The stack ia automatic (static) data storage. It is used via the following:

Local data allocated by callee
• e.g. C automatic variables.
• Procedure frame $fp (activation record) is used by some compilers to manage stack storage.

66
Q

What is procedure calling?

A

Procedure calling is simply the act of executing an instruction.

67
Q

What are the steps required for a procedure call?

A

Steps required:

  1. Place parameters in registers
  2. Transfer control to procedure (callee)
  3. Acquire storage for procedure
  4. Perform procedure’s operations
  5. Place result in register for caller
  6. Return to place of call
68
Q

What is a basic block

A

A basic block is a sequence of instructions with
• No embedded branches (except at the end)
• No branch targets (except at the beginning)

69
Q

Why are basic blocks important?

A

These are important because:
• A compiler identifies basic blocks for optimization
• An advanced processor can accelerate
execution of basic blocks

70
Q

What are the procedure call instructions and how are they used?

A

Procedure call: jump and link
jal ProcedureLabel
• Address of the following instruction put in $ra
• Jumps to target address
• Procedure return: jump register
jr $ra
• Copies $ra to program counter
• Can also be used for computed jumps
• e.g., for case/switch statements

71
Q

What is a leaf procedure

A

A leaf procedure is one that doesn’t call any other procedures.

72
Q

What are non-leaf procedures?

A

Procedures that call other procedures
• For nested call, caller needs to save stuff on the stack:
• Its return address
• Any arguments and temporaries needed after the call
• Restore from the stack after the call

73
Q
A