CSO4 MIPS ISA Flashcards

1
Q

WHAT IS ISA

A

problem: new hardware requires new software and programming language

solution: hardware abstraction
ISA instruction set architecture does that
it’s an abstraction level between software and hardware
takes the software translates it to instructions that are compatible with CPU so that programs and programming languages are portable
usually ISA is built in with the system and is same for a CPU family (example: a lot of intel CPUs have the same ISA)

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

STACK-BASED ISA

A

easy:
-compiler design
-CPU design

no registers only use stack(memory)
for operation:
-push data from top of stack
-execute
-pop to top of stack

this method is slow since we have to constantly interact with memory

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

ACCUMULATOR-BASED ISA
AND EXTENDED

A

one register for arithmetic operation
result is saved in same register
every instruction has one of the values in memory

a=b+c
accum = mem[addr(b)]
accum = accum + mem[addr(c)]
variables in memory
no assisting registers

-still slow cause of memory interaction
-too many instructions for one operation
-bottleneck in accumulator

+easy to make compilers
+easy programming
+easy hardware

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

EXTENDED ACCUMULATOR BASED ISA

A

improved accumulator based ISA
uses special purpose registers
-for indexing , arithmetic operations

arithmetic operations can be done with only registers as arguments but we still use memory sometimes

there are a couple of registers so no bottlenecking problems

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

GENERAL-PURPOSE REGISTERS ISAs

A

Complex Instruction Set Computer(CISC)
can have:
mem- mem
reg-mem
instructions

Reduced Instruction Set Computer(RISC)
can only have reg-reg instructions
use load/store to access memory

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

BASIC DESIGN PRINCIPLES

A
  1. simplicity favors regularity
  2. smaller is faster(less complex)
  3. common case fast(make widely used instructions faster)
  4. good design == good compromises
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

MIPS PROCESSOR - MEMORY

A

Microprocessor without Interlocked Pipeline Stages ( focuses on good pipelining)

RISC ISA
1. reserved stack (external cards)
2. stack begin(extends downwards)
—————free space—————-
if stack and data segment cross over we get out of memory exception
3. data segment(stored data, extends upwards)
4. text segment( this is where code is)
5. reserved(by OS for interrupt handlers, i/o interactions)

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

MIPS ISA

A

instructions are all 32 bits (4 bytes) in MIPS32 and have 3 operands
predetermined length
we care more about how easily it is used by compilers than programmers

instructions:
-computational
-load/store
-jump/branch
-float
-memory management
-special

3 formats: r, i, j

registers are:
-general purpose
-hi, lo
-pc(program counter)

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

THE 32 REGISTERS

A

$zero -> hardwired to value 0 [use not change contents]
$at -> reserved for the assembler [not change contents]
$v0-v1 -> returned values (usually from syscalls)
$a0-a3 -> arguments(usually for syscalls and procedure calls)[preserves procedure call]
$t0-t9 -> temporaries
$s0-s7 -> saved values [preserves procedure call]
$gp -> global pointer
$sp -> stack pointer (basically program counter)
$fp -> frame pointer
$ra -> return address (use for return from procedure calls)

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

ALIGNMENT

A

MIPS memory
-array of:
–bytes
–halfwords (2 bytes)
–words (4 bytes)
we access them with the mem address of the first byte

processor has 32 buses and memory is organized in groups of 32 bits hence we can read 32 bits at once
stored items must occupy the first byte of the group
if it starts elsewhere cannot be read in one go
we get unaligned memory error (fix by adding .align 2 after every data segment initialized)

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

BIG ENDIAN - LITTLE ENDIAN

A

2 ways we can store and read bytes
most significant byte -> least significant byte (big endian)
least significant byte -> most significant byte (little endian)
usually we prefer little endian

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

R FORMAT ARITHMETIC INSTRUCTIONS

A

op code (6) | source reg(5) | reg1(5) | reg2(5) | shift amount(5) used for offset | function type(6)

source is destination
operation between reg1 and reg2

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

I FORMAT ARITHMETIC INSTRUCTIONS

A

op code (6) | source register (6) | reg1 (6) | immediate(16)

common case fast
common to use small constants so we put them in immediate
less load instructions

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

LOAD/STORE (I FORMAT)

A

immediate field is for mem address
there is options for word halfword and byte

we basically gave register address as base address of an array and immediate field as index

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

MIPS ARITHMETIC INSTRUCTIONS

A

add (r)
addi (i) immediate
addiu (i) immediate unsigned
addu (r) unsigned

lui (i) load upper immediate

slt (r) set on less than
slti (i) -//- immediate
sltiu (i) -//- immediate unsigned
sltu (r) -//- unsigned

sub (r) subtract
subu (r)unsigned

div divide
divu -//- unsigned
mult multiply
multu -//- unsigned
mfhi move from hi register
mflo move from lo register
mthi move to hi register
mtlo move to lo register

nor (r) -> not is nor with $zero for simplicity
and (r)
andi (i)
or (r)
ori (i)
xor (r)
xori (i)

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

MIPS MEMORY INSTRUCTIONS

A

lb (i) load byte
lbu (i) unsigned
lh (i) load halfword
lhu (i) unsigned
lw (i) load word
sb (i) store byte
sh (i) store halfword
sw (i) store word

17
Q

LOGICAL INSTRUCTIONS

A

sll shift left logical
sllv -//- variable (takes shift amount as variable)
srl -//- right logical
srlv -//- variable
sra -//- right arithmetic -> preserves the sign
srav -//- variable

18
Q

DECISION INSTRUCTIONS

A

beq branch on equal
bne branch on not equal

for inequality we use set on less than instructions coupled with the branch ones

19
Q

JUMP

A

j type
has op and jump target(26 bits)
target is shifted left by 2 and ored with the 4 msbs of program counter

jr jump register:
goes to the address contained in register
is a little bit slower

20
Q

PROCEDURES

A

uses:
jal x to jump to procedure-callee
-> this store return address
jr $ra to return to caller
-> results go to $v0-v1

when we have more variables or return values than the available registers?
we use stack with stack pointer
addi $sp , $sp, -4spaces we need - reserve space in the stack
store at $sp with offset (must be multiple of 4)
addi $sp, $sp, 4
spaces we used and dont need - frees up the stack

21
Q

NESTED PROCEDURES

A

leaf procedures do not call others but that is not always the case
–one example is recursion

22
Q

STRCPY

A

computer likes numbers but sometimes programs need strings
we use ascii for that (1 byte per char)
and use lb(loads 1byte in LSBs of reg) and sb (stores LSbyte in memory)
strcpy in assembly

C code:
void strcpy(char x[], char y[])
{int i = 0;
while ((x[i] = y[i]) != ‘\0’){//’\0’ is termination character
i++;}}

asl code:
strcpy:
addi $sp, $sp, -4 #space for $s0 in stack
sw $s0, 0($sp) #offset 0 from $sp
add $s0, $zero, $zero #$s0 = 0 is i
L1:
add $t1,$s0,$a1 # add i to base address of y and store in $t1
lb $t2,0($t1) # load y[base address y+i] in $t2
add $t3, $s0,$a0 # add i to base address of x and store in $t2
sb $t2,0($t3) # store y[base address y+i] which is in $t2 in x[base address x +1]
beq $t2, $zero,L2 # check termination symbol and jump to closing routine
addi $s0, $s0, 1 # i++
j L1 #else do loop

L2:
lw $s0, 0($sp) # get what we store in stack
addi $sp, $sp, 4 # undo stack allocation
jr $ra # resume main program