Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

EN-6110 Computer Architecture

EN-7110 Advanced Computer


Architecture
Lecture # 3
RISC-V Assembly Language

Dr. Syed Azhar Ali Zaidi


Assistant Professor
1
Components of a Computer

2
Levels of Representation/Interpretation

3
Assembly Language

4
5
Mainstream ISA

6
Variables in Hardware

7
Registers vs. Memory

8
RISCV Registers

– Registers are 32-bit (word), 64-bit (doubleword) and


128-bit (quadword) in RV32, RV64 and RV128 bit
variants.
• Why 32? Because smaller is faster. But too small
is bad.
• Also affect the number of bits in the instruction
format.
9
RISCV Registers
• x0 is special registers which holds value zero.
• Registers can also be accessed by their names
(discussed later)
• Operation in RISCV can only be performed on
registers.
• Compiler must carefully put together the code in
order to efficiently use registers.
• Registers have no type. The operation performed
determine how the data in register is treated.
10
RISCV Instructions
• Each line of assembly language contains at
most 1 instruction
• Instructions are closely related to the common
high-level language operations.
add x1, x2, x3
add x1, x1, x4

11
RISCV Instruction Syntax

• 1 operator, 3 operands
• Keep hardware simple via regularity.

12
RISCV Addition and Subtraction

13
RISCV Arithmetic: Example1

14
RISCV Arithmetic: Example2

15
Zero Register

add x5, x0, x0 # x5 = 0


add x1, x2, x0 # x1 = x2

16
Constant or Immediate Operands

• Make common case fast! Constants are so frequent in programs.


• NOP – addi x0, x0, 0
17
Memory Operands – Data Transfer

18
Memory Operands – Data Transfer
• Load

• Store

• Different variations of load and store instructions:


– ld, lw, lh, lb, lwu, lhu, lbu
– sd, sw, sh, sb store 64-bit, 32-bit, 16-bit and 8-bit from the
low bits of register to memory
– In 128 bit variant lq and sq are added to load and store
128-bit values

19
Memory is Byte-Addressed

20
Big Endian vs. Little Endian

21
Data Transfer Instructions - Examples

22
Data Transfer Instructions - Examples

23
Alignment Restriction

24
RISC-V Logical Instructions

25
RISC-V Logical Instructions

26
Logical NOT Operation in RISCV

27
Logical Shifting

28
Arithmetic Shifting

29
Decision Making Instructions

30
Types of Branches

31
Example if Statement

32
Example if-else Statement

33
Other Conditional Branch Instructions

34
Loops in C/Assembly

35
C Loop Mapped to RISCV Assembly

36

You might also like