RISC-V Instruction Set Architecture (ISA)
RISC-V Instruction Set Architecture (ISA)
Architecture (ISA)
Introduction
Machine Instruction Characteristics
Types of Operands
Addressing Modes
Instruction Formats
Program execution
Summary
Instruction Set Architecture
(ISA)
Introduction ❑ Overview
Machine Instruction Characteristics
❑ Hierarchy of Computer Languages
Types of Operands ❑ General Concepts:
Addressing Modes RISC-V Processor Architecture
Instruction Formats
Program execution
Summary
Overview
computer
programmer
computer
designer
3
Hierarchy of Computer Languages
• A programming
language that uses
symbolic names to
represent operations, • Instructions consist
registers and of 0’s and 1’s.
Microprogram control
memory locations. • Directly executed by
• Readability hardware
4
Compiler and Assembler HLL
Faster, easier, portable
Assembly
Accessible to system hardware.
Efficiency: control over hardware,
more compact coding
Learn how to develop compiler.
Learn how to design an ISA.
clock
ALU
Register/Memory
control
Register file
8
5-Stage RISC-V – instruction execution cycle
Introduction
Machine Instruction ❑ Elements of a Machine
Characteristics Instruction
Types of Operands
Addressing Modes ❑ Instruction Representation
Instruction Formats ❑ Instruction Types
Program Execution
❑ Number of Addresses
Summary
❑ Instruction Set Design
Elements of an Instruction
Elements Description
Operation code o Specifies the operation to be performed a
binary code (e.g., lw, sw, add, sub).
(Opcode)
Source operand o The operation may involve one or more
reference source operands, that is, operands that are
inputs for the operation.
Result operand o The operation may produce a result.
reference
(Destination).
Next instruction o This tells the processor where to fetch the
reference next instruction after the execution of this
instruction is completed. Invisible
11
+ Example: Elements of an instruction
Source Operand
Destination
Operand
Opcode
• 32-bit addresses
• indicate the relative byte
distance of each statement
from the beginning of the
program’s code area
• assembly language instructions, each 4
bytes long
◼ Generally, Source and Destination operands can be in one
of four areas:
15
Operand: From Operand: Memory
I/O
Example 2:
Operand: Register Operand:
Immediate value
Next instruction is
where ELSE is located,
offset 12 from the line
lw x20,Total 10000a17
lw x21, stuff 000a2a03
add x20, x20, x21 10000a97
la x18, Total ffcaaa83
sw x20,0(x18) ……
19
Instruction format
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.469. 20
Machine Instruction Representation
R
I
U
S
SB
UJ
21
Instruction Types
Instruction
Types
Imm[10:0] Imm[4:1]
(UJ-type)
27
+ Example 1: Deriving instruction
machine code from assembly code
line Assembly code Machine code Machine
(bin) code (hex)
58: myMult: …
… ……..
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.432. 28
Example: Program to execute PUSH C
PUSH D
PUSH E
4 instructions MUL
ADD
PUSH B
6 instructions PUSH A
SUB
10 instructions
DIV
POP Y
(d) No-address
instruction
8 instructions
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.417. 29
How Many Addresses?
30
◼ Four common instruction formats:
31
Instruction Set Design
◼ The most important of these fundamental design issues include
the following: o How many operations?
o What can they do?
Operation o How complex are they?
o The mode(s)
by which the
Addressing Data Types
address of an
operand is
o The various
specified.
types of data.
Instruction
Registers
Formats
Introduction
Machine Instruction
Characteristics
Data types
Addressing Modes
Instruction Formats
Program Execution
Summary
Overview
34
35
Example : various lengths of data.
lh x10, 0(x7)
Half-word
lw x10, 0(x7)
Word
36
Example 2: various length of data
register register
37
Example: data length for floating point.
38
Instruction Set Architecture
(ISA)
Introduction ❑ Overview
Machine Instruction ❑ Immediate Addressing
Characteristics
❑ Direct Addressing
Types of Operands
❑ Indirect Addressing
Addressing Modes
Instruction Formats ❑ Register Addressing
Program execution ❑ Register Indirect Addressing
Summary ❑ Displacement Addressing
Overview
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.474. 40
Notations: A = contents
of an address
field in
instruction.
R = contents
of an address
field in
instruction that
refers to a
register.
EA = actual
(effective)
address of the
location
containing the
referenced
operand.
(X) = contents
of memory
Figure: Addressing modes. location X or
register X.
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.458. 41
operand
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.476. 43
(c) Indirect Addressing
Look in A, find
address (A), and look
there for operand.
◼ Solution for the limitation of
the address range in direct
addressing → to have the
address field address of a
word in memory, full-length
address of the operand.
Not in RISC-V, not in x86
Three or more memory
references could be required
No particular advantage.
to fetch an operand; slower.
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.477. 44
(d) Register Addressing
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.476. 45
(e) Register Indirect Addressing
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.478. 46
(f) Displacement Addressing
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.478. 47
(f.1) Relative Addressing
◼ Also called PC-relative addressing, the implicitly referenced register is
the Program Counter (PC).
R = PC
EA = A + (PC)
◼ The next instruction address (shown in PC) is added to the address
field to produce the EA.
48
Offset = Target – Source
= ELSE – PC
Displacement Addressing. = 2c – 20
= c (hex) or 12(dec)
PC=20
Need to go to
ELSE which i
in 0000002c
49
(f.2) Base-Register Addressing
EA = A + R
o A holds displacement.
o R holds pointer to base address.
EA = sign(imm11:0) + rs1
50
Displacement Addressing.
register content
Base-register s3
displacement
addressing
s4
t0
base
t1
t2
a0
a7
Assume data segment
(f.3) Indexed Addressing
EA = A + R
o A = base
o R = displacement
o Good for accessing arrays
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.479. 52
.data
X86 array1 byte 10h,11h,12h,13h
Displacement Addressing. array2 word 123h,234h,345h,456h
array3 dword 123456h, 23456789h
L1:
mov bx, array2[eax]
add eax,2
call dumpregs
LOOP L1
exit Displacement
main ENDP
53
Table: Basic addressing modes.
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.459. 54
Instruction Set Architecture
(ISA)
Introduction
Machine Instruction
Characteristics
Types of Operands
Addressing Modes ❑ Simple statement
Program execution ❑ Conditional statement
X86 Instruction Formats ❑ Calling a procedure
Summary
❑ Calling a nested procedure
Program execution
(a simple statement)
◼ Example 1:
f= (g+h) – (i+j)
56
memory
0x 1000 0000 21 1e
(a simple statement) 0x 1000 0001 00 00
0x 1000 0002 00 00
◼ Example 2: 0x 1000 0003 00 00
0x 1000 0004 06 06
g= h + A[8] 0x 1000 0005 00 00
0x 1000 0006 00 00
0x 1000 0007 00 00
0x 1000 0008 10 10
0x 1000 0009 00 00
0x1000 000A 00 00
0x 1000 000B 00 00
0x1000 000C 11 11
0x1000 000D 00 00
0x1000 000E 00 00
0x 1000 000F 00 00
0x 1000 0010 12 12
0x 1000 0011 00 00
0x 1000 0012 00 00
0x 1000 0013 00 00 57
Program execution
(a conditional statement)
◼ Example 3:
if(i==j)
f=g+h;
else
f=g-h;
58
Program execution
(calling a procedure)
a0 0000 0004
a1 0000 0003
s0 Caller’s fp
sp 7fff fff0
7fff_ffd1
7fff_ffd0
60
Program execution
(calling a procedure)
0x50:
7fff_ffed
7fff_ffec
a0 0000 0004
a1 0000 0003
s0 Caller’s fp
sp 7fff fff0
ra 0000 0030 7fff_ffd1
7fff_ffd0
61
pc= 0000 0050
Program execution
(calling a procedure)
3. Acquire the registers
required by the procedure;
stack
- Allocate stack frame
- Push in the registers
sp 7fff_fff0
7fff_ffef
7fff_ffee
a0 0000 0004
a1 0000 0003
s0 Caller’s fp
sp 7fff ffd0
ra 0000 0030
7fff_ffd1
sp 7fff_ffd0
pc= 0000 0050
Program execution
(calling a procedure)
3. Acquire the registers
required by the procedure;
stack
- Allocate stack frame
- Push in the registers
sp 7fff_fff0
7fff_ffef
7fff_ffee
00000030
sp 7fff_fff0
7fff_ffef
7fff_ffee
00000030
Caller’s
a0 0000 0004
fp
a1 0000 0003
ra 0000 0030 7fff_ffe8
sp 7fff ffd0
s0 Caller’s fp
sp 7fff_ffd0
Program execution
(calling a procedure)
3. Acquire the registers
required by the procedure;
- Allocate stack frame
- Push in the registers
fp sp 7fff_fff0
7fff_ffef
7fff_ffee
00000030
Caller’s
a0 0000 0004
fp
a1 0000 0003
ra 0000 0030 7fff_ffe8
sp 7fff ffd0
s0/fp 7fff fff0
sp 7fff_ffd0
3. Acquire the registers
fp sp
Program execution
7fff_fff0
required by the procedure;
7fff_ffef
- Allocate stack frame
7fff_ffee
(calling a procedure) 00000030
- Push in the registers
7fff_ffed
7fff_ffec
Caller’s fp
7fff_ffe8
00000003
7fff_ffe0
a0 0000 0004
a1 0000 0003
ra 0000 0030
sp 7fff ffd0
s0/fp 7fff fff0
sp 7fff_ffd0
fp sp
Program execution
7fff_fff0
7fff_ffef
7fff_ffee
(calling a procedure) 7fff_ffed
7fff_ffec
00000030
Caller’s fp
00000004
7fff_ffe4
00000003
7fff_ffe0
a0 0000 000c
a1 0000 0003
ra 0000 0030 4. Perform the
sp 7fff ffd0 procedure task
s0/fp 7fff fff0
sp 7fff_ffd0
fp sp
Program execution
7fff_fff0
7fff_ffef
7fff_ffee
(calling a procedure) 7fff_ffed
7fff_ffec
00000030
Caller’s fp
00000004
7fff_ffe4
00000003
7fff_ffe0
a0 0000 000c
a1 0000 0003
ra 0000 0030
sp 7fff ffd0
s0/fp 7fff fff0
Caller’s fp
7fff_ffe8
00000004
7fff_ffe4
00000003
7fff_ffe0
a0 0000 000c
a1 0000 0003
6. Return control
ra 0000 0030
-retrieve ra, s0/fp
sp 7fff ffd0 - Pop / free the stack
s0/fp Caller’s fp frame
sp 7fff_ffd0
Program execution
(calling a nested procedure)
Program execution
(calling a nested procedure) Executing main
fp 7fff_fff0
Return address, ra
32-byte
Caller’s frame pointer
Argument registers
………
7fff_ffd0
0x00c0:
0x0030:
Program execution Executing addmult
(calling a nested procedure) 7fff_fff0
Return address, ra
32-byte
Caller’s frame pointer
Argument registers
………
fp 7fff_ffd0
Return address, ra
32-byte
Argument registers
………
7fff_ffb0
0x00c0:
0x0030:
Program execution Executing add
(calling a nested
7fff_fff0
procedure)
Return address, ra
32-byte
Caller’s frame pointer
Argument registers
………
7fff_ffd0
Return address, ra
32-byte
Argument registers
………
fp 7fff_ffb0
Return address, ra
32-byte
Caller’s frame pointer
………
7fff_fe90
Program execution Return to addmult
(calling a nested procedure) 7fff_fff0
Return address, ra
32-byte
Caller’s frame pointer
Argument registers
………
fp 7fff_ffd0
Return address, ra
32-byte
Argument registers
………
7fff_ffb0
0x00c0:
0x0030:
Program execution
(calling a nested procedure)
fp
Return to main
7fff_fff0
Return address, ra
32-byte
Caller’s frame pointer
Argument registers
………
7fff_ffd0
0x00c0:
0x0030:
Activity: https://ripes.me/ (RISC-V online assembler)
Instruction Set Architecture
(ISA)
Introduction
Machine Instruction
Characteristics
Types of Operands
Addressing Modes
X86 Instruction Formats
Summary
x86 Instruction Format
+ x86 Instruction Format
+ x86 Instruction Format
+ x86 Instruction Format
+ x86 Instruction Format
+ x86 Instruction Format
+ x86 Instruction Format
+x86: add instruction
+x86: add instruction
Instruction Length
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.473. 88
4.6 Summary
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.413, 457. 89