CMPEN 331 - Quiz 2-3

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/37

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

38 Terms

1
New cards

add $t0, $s1, $s2

$t0 = $s1 + $s2

Add values in two registers

2
New cards

sub $s0, $t0, $t1

$s0 = $t0 - $t1

3
New cards

lw $t0, 32($s3) 

32 = offset, $s3 = base register, $t0 = source register

$t0 = arr[8]

Load word from memory at address $s3 + 32 into $t0

4
New cards

sw $t0, 48($s3)

48 = offset, $s3 = base register, $t0 = source register

Store word from register $t0 into memory at address $s3 + 48

5
New cards

addi $s3, $s3, 4

$s3 = $s3 + 4

Add constant to a regsiter

6
New cards

$zero

constant 0, can’t be overwritten

7
New cards

$t0 - $t7 - reg’s 8-15
$t8 - $t9 - reg’s 24-25
$s0 - $s7 - reg’s 16 - 23

Register numbers (Temporary values [caller-saved] and Saved values [callee-saved])

8
New cards

op | rs | rt | rd | shamt | funct
special | #s1 | $s2 | $t0 | 0 | add
0 | 17 | 18 | 8 | 0 | 32
000000 | 10001 | 10010 | 01000 | 00000 | 100000

000000100011001001000000001000002 = 0232402016

R-format Example:
add $t0, $s1, $s2
$s1 = 17, $s2 = 18, $t0 = 8, add = 32

9
New cards

sll $t0, $t1, 2

Shift left # $t0 = $t1 << 2

10
New cards

srl $t0, $t1, 1

Shift right # $t0 = $t1 >> 1

11
New cards

and $t0, $t1, $t2
andi $t0, $t1, immediate (constant)

Bitwise AND # $t0 = $t1 & $t2

12
New cards

or $t0, $t1, $t2
ori $t0, $t1, immediate (constant)

Bitwise OR # $t0 = $t1 | $t2

13
New cards

nor $t0, $t1, $t2
nor $t0, $t1, $zero

Bitwise NOT # $t0 = !($t1 | $t2)

14
New cards

beq rs, rt, L1

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

15
New cards

bne rs, rt, L1

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

16
New cards

j L1

unconditional jump to instruction labeled L1

17
New cards

li $v0, 10
syscall

Trigger system call to exit program. AKA Exit: …

18
New cards

sll $t1, $s3, 2 # Temp register $t1 = i * 4

Multiply the value $s3 by 4 and store it in $t1.

19
New cards

slt $t0, $s1, $s2
bne $t0, $zero, L

if ($s1 < $s2)
branch to L

20
New cards

slt rd, rs, rt #sltui = unsigned comparison

if (rs < rt) → rd = 1; else rd = 0

21
New cards

slti rt, rs, constant #sltu = unsigned comparison

if (rs < constant) → rt = 1; else rt = 0;

22
New cards

slt $t0, $s0, $s1 # signed
sltu $t0, $s0, $s1 # unsigned

-1 < +1 → $t0 = 1
+4,294,967,295 > +1 → $t0 = 0

23
New cards

ble $s1, $2, Label

bgt $s1, $2, Label

bge $s1, $2, Label

s1 <= s2 → Label
s1 > s2 → Label
s1 >= s2 → Label

24
New cards

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

Procedure Calling

25
New cards

• $a0 – $a3: arguments (reg’s 4 – 7)
• $v0, $v1: result values (reg’s 2 and 3)
• $t0 – $t9: temporaries
           
• Can be overwritten by callee (calling program)
• $s0 – $s7: saved
           • Must be saved/restored by callee
• $gp: global pointer for static data (reg 28)
• $sp: stack pointer (reg 29)
• $fp: frame pointer (reg 30)
• $ra: return address (reg 31)

Register Usage

26
New cards

jal ProcedureLabel

Procedure call: jump and link

27
New cards

jr $ra

Procedure return: jump register

28
New cards

mul t0, t1, t2

t0 = t1 * t2

29
New cards

op = 0×00
register-to-register operations.
e.g., add, addu, sub, subu, and, or, slt, sltu, sll, srl, jr, nor

R-type instructions
op(6), rs(5), rt(5), rd(5), shamt(5), funct(6)

30
New cards

op ≠ 0×00, 0×02, 0×03
use immediate values for loads, stores, and branches
e.g., lw, sw, beq, bne, addi, addiu, andi, ori

I-type instructions
op(6), rs(5), rt(5), immediate(16)

31
New cards

op = 0×02, 0×03
Used for jumps with a 26-bit target address
e.g., j & jal

J-type instructions
op(6), constant/address(26)

32
New cards

op ≠ 0×00, 0×02, 0×03
Used to branch to instructions
e.g., bne, blt, beq, etc.

Branch Addressing (I-type instruction)
op(6), rs(5), rt(5), constant/address(16)

33
New cards

move $t0, $t1
blt $t0, $t1, L

Psuedoinstructions:
add $t0, $0, $t1

slt $at, $t0, $t1
bne $at, $0, L

34
New cards

jal Function
jr $ra

Call a function (jump and link)
Return to instruction where call was made (continue)

35
New cards

lb rt, offset(rs)
lbu rt, offset(rs)

load a byte from memory, placing it in the rightmost 8 bits of a register.

#Read byte from source

36
New cards

sb rt, offset(rs)

37
New cards

lui, rt, constant

Load Upper Immediate
Copies 16-bit constant to left of 16 bits of rt
Clears right 16 bits of rt to 0

38
New cards

Load 32 bit constant into register $s0
lui $s0, 61
ori $s0, $s0, 2304

0000 0000 0011 1101 0000 1001 0000 0000
0000 0000 0011 1101 0000 0000 0000 0000
0000 0000 0111 1101 0000 1001 0000 0000

Explore top flashcards