Lecture 02
Lecture 02
Exec Decode
add a, b, c // a gets b + c
f = (g + h) - (i + j);
• Compiled RISC-V code:
ld x9, 64(x22)
add x9, x21, x9
sd x9, 96(x22)
• Instruction Fields:
• opcode: operation code
• rd: destination register address
• funct3: 3-bit function code (additional operation code)
• rs1: first source register address
• rs2: second register address
• funct7: 7-bit function code (additional operation code)
(00000001010110100000010010110011) 2=(015A04B3)16
• The data is loaded into (lw) or stored from (sw) a register in the
register file – a 5 bit address
• The memory address – a 32 bit address – is formed by adding the
contents of the base address register to the offset value
• A 12-bit field meaning access is limited to memory locations within a region
of 211 or 2,048 bytes of the address in the base register
• Note that the offset can be positive or negative
• I Format Instruction
• rs1: source or base register address
• immediate: small constant operand or offset added to base
address, 2’s complement, sign extended
• S Format instruction
• Different immediate format for store instructions
• rs1: base address register number
• rs2: source operand register number
• immediate: offset added to base address
• split so that rs1 and rs2 fields always in the same place
offset
sign-extend
00
branch dst
32 32
Add
address
PC 32
32 Add
32
32
4
32 ?
• f, g, … in x19, x20, …