Lab02 Riscv Ict
Lab02 Riscv Ict
Goals
After this lab session, you will understand modules of computer system, how it works
by debugging simple instructions of a RISC-V Processor. You also know and use basic
assembly instructions and find out the nature of CPU Architecture, exploit debug tools
to verify knowledge of Computer Architecture and Instruction Set. Remember some
common Compiler Directives which are used to guide RARS complete source code
correctly.
References
o RISC-V documents, lecture notes.
o The RISC-V Instruction Set Manual: riscv-spec-20191213.pdf
Home Assignment 1
Survey and try to have a glance of computer architecture: CPU, Memory, IO Modules
and System Interconnection (Bus); Programming Model; Dataflow; Instruction Set
Architecture;
A set of registers, called Register File, act as built-in variables inside the CPU.
Developers use registers as command variables, pointer variables point to difference
locations in the main memory such as Operating System, Text Segment, Data
Segment, Stack…
Hanoi University of Science and Technology
School of Information and Communications Technology
Home Assignment 2
Read more about RISC-V architecture, remember fundamental knowledge as below:
o Names and meanings of 32 registers
o Dedicated registers PC, IR
o The simplest Instruction Set called RV32I. its extension with letters more
+ letter M: supports Multiplication
+ letter C: support compacted instruction with the length of 16-bit
For example, RV32IMC, RV32IM, etc.
o The RV32I has about 40 instructions which are classified into 6 groups, called
instruction formats: R, I, S, B, U, J.
Home Assignment 3
On the menu, select Help / click Help.
o Click on tab Directives. Understand .asciiz, .byte, .word .data, .text
1
Hanoi University of Science and Technology
School of Information and Communications Technology
On the other hand, instruction addi format is I type. I format save 12-bits to store 12-
bit signed integer (imm[11:0]). As a result, addi just assign a small integer in the range
of 12-bits (from -2048 to 2047).
Requirements:
Requirements:
Note:
- In RISC-V, the constant (immediate value) is always 2’s complemented, should
be extend to 32-bit 2's complement numbers, to fit the length of register.
# Laboratory Exercise 2, Assignment 2
# IN HIGH LEVEL LANGUAGE
# int a = 0xFEEDB987;
# IN ASSEMBLY LANGUAGE
.text
lui s0, 0xFEEDC # s0 = 0xFEEDC000
addi s0, s0, 0xFFFFF987 # s0 = 0xFEEDB987
3
Hanoi University of Science and Technology
School of Information and Communications Technology
Requirements:
- Compile, observe and compare the commands in the Source column and the Basic
column in the Text Segment window. Explain the results.
# Expression Z = 2X + Y
add s0, t1, t1 # s0 = t1 + t1 = X + X = 2X
add s0, s0, t2 # s0 = s0 + t2 = 2X + Y
Requirements:
4
Hanoi University of Science and Technology
School of Information and Communications Technology
Assignment 5: Multiplication
Support: Multiplication is quite different from other mathematical instructions, because
when multiplying two 32-bit numbers, the result is a 64-bit number. The RISC-V
architecture provides different instructions for performing multiplication, which can
write the result as 32-bit or 64-bit, depending on the instruction. These instructions are
not part of the RV32I basic architecture, but are part of the RV32M extension (RISC-V
multiply/divided extension).
# Expression Z = X * Y
mul s1, t1, t2 # s1 just stores the low 32 bits of the result
Requirements:
From the perspective of CPU, both instructions and data are binary numbers. cannot.
5
Hanoi University of Science and Technology
School of Information and Communications Technology
The directive .data and .text works as bookmarks, locate the start address of a certain
memory area in RAM, where the compiler will set the first variable or the first
instruction. This starting point is purely a convention for controlling resources, so each
CPU, each operating system, or compiler can set different starting points.
The example below shows 2 directives .data and .text for allocating and initializing
global variables, defining constants, variables loaded into the data segment, and the code
loaded into the text segment. (Understand how the program works).
Requirements:
6
Hanoi University of Science and Technology
School of Information and Communications Technology
Support: you could declare directives .data, .text with syntax below
.data literal_address
.text literal_address
The literal address is the start address of the memory area. The compiler will allocate
variables or instructions from this address onwards.
Consequences:
- Value of variables could be changed, but its address is fixed (Ignore
virtualization techniques or operating system).
- The address of an instruction is fixed.
Note:
- If you can find out the address of a variable of a target software, you can
develop another software to illegally access that variable and change its value.
That is hacking.
- If you can find the address of a instruction of a target software, you can
develop another software to replace that instruction by a jump instruction to
make CPU move to your codes. That is a computer virus.
Conclusion