Comp Org - RISC-V stuff

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/46

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.

47 Terms

1
New cards

.ascii vs .asciz

.ascii: No null terminating

.asciz: Produces null terminating

Null terminating different from newline (\n)

2
New cards

How many bits can each register hold?

32 bits / 4 bytes = 1 word

3
New cards

Number of bits it takes to store an address

32 bits / 4 bytes = 1 word

4
New cards

How many registers does RISC-V have?

32 registers

5
New cards

rd meaning on reference card

desination register

6
New cards

rs1/rs2 meaning on reference card

first source register/second source register

7
New cards

imm meaning on reference card

immediate - a constant number

8
New cards

pseudocode for how you would do this in risc-v

a = b + c + d - e

temp = b + c

temp = temp + d

a = temp - e

9
New cards

Rars code to do “a = b”.

a is stored in s0

b is stored in s1

add s0, s1, zero

10
New cards

How to subtract immediates in rars

f = g - 10

f is stored in s0

g is stored in s1

addi s0, s1, -10

11
New cards

System call syntax in RISC-V

addi a7, zero, sys_call_number

ecall

  • a7 is special register for system calls

  • Call is stored in a0

12
New cards

Sys call numbers

Remember - int, float, double, string

1 - print int

2 - print float

3 - print double

4 - print string

5 - read int

6 - read float

7 - read double

8 - read string

10 - exit

13
New cards
<p>Explain each memory segment</p>

Explain each memory segment

Stack: stores local variables and function memory, i.e. s0, s1

Dynamic Data: Used when a .space is used in .data segment

Static Data: Used when a .word is used in .data segment

Text: Stores the machine code version of the assembly code

Reserved: Off use for code and reserved for special uses.

14
New cards

Each memory address points to a specific ___ (byte or bit?)

byte, bits aren’t stored.

If 0×1000 is a byte, next byte is at 0×1001

15
New cards

Sequential address of words differ by __ (the number)

4, since 1 word is 4 bytes

16
New cards

Memory —> Register

lw, load word

17
New cards

Register —> Memory

sw, store word

18
New cards

Load word syntax

lw rd, byte_offset(rs1)

rs1 = register containing pointer to memory

rd now contains the value at rs1 + byte_offset

19
New cards

Store word syntax

sw rs2, byte_offset(rs1)

rs2 = register containing memory you want to store

rs1 now contains the value at rs2 + byte_offset

20
New cards

Issue with lb

What to do with the rest of the 24 bits in the 32 bit register?

  • Sign extend

  • Or zero extend is lbu (load bit unsigned)

Same idea with loading half words (2 bytes)

21
New cards

Concept of Alignment with memory

Objects must fall on address that is a multiple of their size

22
New cards

How to know if something is Word aligned, Byte Aligned, Half word Aligned

Word aligned: Last hex number is a multiple of 4 (i.e. 0,4,8,C) OR binary representation of last hex number has low 2 bits of 00

Byte aligned: Last hex number can be anything

Half word aligned: Last hex number is a multiple of 2 (0,2,4…,A,C,E) OR binary represnetation of last hex number has low 1 bit of 0

23
New cards

Thing to use to ensure alignment (What section its used in and the order to use it)

.align n - ensures next field is aligned to a multiple of 2^n

Use before doing a .word or .text in .data

24
New cards

Little Endian vs big endian

Example with storing 0×00007ffe

Key point about how they are grouped (based on size of hex)

little endian - stores little end of number first

big endian - stores big end of number first

Size of hex is 4 bits. Since each memory cell is 1 byte in this case, 2 hex values to get 8 bits = 1 byte.

<p>little endian - stores little end of number first</p><p>big endian - stores big end of number first</p><p></p><p>Size of hex is 4 bits. Since each memory cell is 1 byte in this case, 2 hex values to get 8 bits = 1 byte.</p>
25
New cards

difference between .space and .word (also what section they go in)

Section: .data

.space 4 - allocates 4 bytes, uninitialized

.word 0 - 4 bytes, initialized to 0 (since 0 is int and int has 4 bytes)

26
New cards

In logical operators, numbers for True and False

True - 1

False - 0

27
New cards

What to do instead of a not

How to do not t0, t2

xori with -1 (all 1’s)

xori t0, t2, -1

28
New cards

and can be used to __

mask

Since and with 0 produces 0, with 1 produces original bit…

Spam 0’s for ones you want to mask, spam 1’s for bits you want to isolate

<p>mask</p><p>Since and with 0 produces 0, with 1 produces original bit…</p><p>Spam 0’s for ones you want to mask, spam 1’s for bits you want to isolate</p>
29
New cards

or can be used to ___

force bits to 1

since or with 0 produces original bit, with 1 produces 1…

Spam 0’s for ones you want to keep, spam 1’s for bits you want to convert to 1

<p>force bits to 1</p><p>since or with 0 produces original bit, with 1 produces 1…</p><p>Spam 0’s for ones you want to keep, spam 1’s for bits you want to convert to 1</p>
30
New cards

Range for immediates

At most 12 bit signed integer

-2^11 —> 2^11 - 1

Meaning, not neccessarily 3 hex numbers. (0×800 —> 0×7FF)

31
New cards

Note for Rars hex values

Rars interprets hex has unsigned. With 32 bits, 0xFFF gets sign extended to 0×00000FFF.

If need 0xFFF as in twos complement -1, need to manually type 0×8 F’s

32
New cards

Logical vs arithmetic shifting

logical - fills empited bits with 0 (doesn’t preserve sign)

arithmetic - fills empied bits by sign extending (preserves sign)

33
New cards

Use case of left and right shifting

Shifting left multiplies original number by 2^n

Shifting right divides original number 2^n

n being the number of bits shifted

34
New cards

Shift syntax (Important note about what is shifted)

Operand rd, rs1, rs2

rs2 - can be register or an immediate value

Shifted by rs2 number of BITS. So if shifting a hex value, essentially moves hex numbers over by rs2/4 positions.

35
New cards

How to know when shift left has overflowed (for signed and unsigned)

Unsigned: First 1 is shifted out of the left edge

Signed: most significant bit changes values

36
New cards

Maximum number of bits that can be loaded with Load Upper Immediate

20 bits

37
New cards
lui t0, 0xFACA
lui t1, 0xFACA0

Difference?

t0 = 0×0FACA000

t1 = 0xFACA0000

Since lui can do 20 bits, 0xFACA gets extended to 0×0FACA.

38
New cards

If statement + syntax (equal to and not equal to)

beq rs1, rs2, label

bne for not equal to

39
New cards

Way to jump directly to label

jal zero, label

40
New cards

2 inequality comparisons in risc-v (with syntax) (signed and unsigned)

blt rs1, rs2, label

bge rs1, rs2, label

To do unsigned comparison…

bltu rs1, rs2, label

41
New cards

Use case of using unsigned comparison

Check IndexoutofBounds errors.

# i = a0, size = a1

bgeu a0, a1, IndexOutofBounds  

If i is negative, twos complement so becomes BIG number.

42
New cards

How to for loop

for (int i=0; i < 100; i++)

Using t0 and t1

  • Put 0 into t0

  • Put 100 into t1

  • Define loop label and increment t0

  • Compare t0 and t1 at end of loop (blt t0, t1, loop)

43
New cards

Array & pointer style for accessing A[i]

Array:

  • Multiply i by 4 to get 4i

  • Add base array address by 4i to index

Pointer:

  • Load base address of the array

  • In a loop up to the number indexed…

    • Add 4 to the base address (Or size of whatever the array is holding)

44
New cards

What is the program counter?

Special register that holds memory location of current instruction to execute

45
New cards

What caller and callee uses to jump

Caller: jal ra, function_name

Callee: jalr zero, ra, 0

46
New cards

How to allocate stack on the space

addi sp, sp -4  # Stack goes down
sw register, 0(sp)  # register is the register of thing wanting to be stored  

47
New cards

How to release space

lw ra, 0(sp)  # Assuming sp is pointing at ra
addi sp, sp, 4
jalr zero, ra, 0  # Jumps back to whatever function