Module 2 Instructions
Module 2 Instructions
1 Introduction
• Instruction set
• Instruction set: The vocabulary of commands understood by
a given architecture.
• Stored-program concept
• Stored-program concept: The idea that instructions and data
of many types can be stored in memory as numbers and thus
be easy to change, leading to the stored-program computer.
2.1 Introduction
• Examples
• A simple Add Instruction
ADD A, B, C
ADD A, B, C
ADD A, A, D
ADD A, A, E
Three Add instructions executes one at a time
2.1 Introduction
d = a - e;
• sub d, a, e
• // register d contains a - e
2.1 Introduction
•
f = (g + h) - (i + j);
• add t0, g, h
• // temp t0 contains g + h
• add t1, i, j
• // temp t1 contains i + j
• sub f, t0, t1
• // f gets t0 - t1, which is (g + h) - (i + j)
2.1 Introduction
Shift right logical srl x5, x6, x7 x5 = x6 >> x7 Shift right by register
Arithmetic Shift right by
Shift right arithmetic sra x5, x6, x7 x5 = x6 >> x7
register
Shift
Shift left logical immediate slli x5, x6, 3 x5 = x6 << 3 Shift left by immediate
Shift right logical immediate srli x5, x6, 3 x5 = x6 >> 3 Shift right by immediate
Shift right logical arithmetic Arithmetic shift right by
srai x5, x6, 3 x5 = x6 >> 3
immediate immediate
2.3 RISC V INSTRUCTION EXAMPLES
Category Instruction Example Meaning Comments
Branch if less than blt x5, x6, 100 if (x5 < x6) go to PC + 100 PC-relative branch if registers less
Jump and link jal x1, 100 x1 = PC+4; go to PC + 100 PC-relative procedure call
Unconditional jump
Jump and link register jalr x1, 100(x5) x1 = PC+4; go to x5 + 100 Procedure return; indirect call
2.4 OPERANDS OF THE COMPUTER HARDWARE
• Word
• Word: The natural unit of access in a computer, usually
a group of 32 bits; corresponds to the size of a register
in the RISC-V architecture.
• Doubleword
• Doubleword: Another natural unit of access in a
computer, usually a group of 64 bits.
2.4 OPERANDS OF THE COMPUTER HARDWARE
• (A) (B)
• load
The data transfer instruction that copies data from memory
to a register is traditionally called load.
• base address
A base address is the starting address of an array in memory.
• base register
A base register is a register that holds an array's base
address.
• offset
An offset is a constant value added to a base address to
locate a particular array element.
2.4 DATA TRANSFER EXAMPLE BASE REGISTER AND OFFSET
2.4 Alignment restrictions – A requirement that data be aligned in memory on
natural boundariesA requirement that data be aligned in memory on natural boundaries.
2.5Signed and Unsigned Numbers
2.4 Significant and Overflow
• Least significant bit
• Least significant bit: The rightmost bit in a RISC-V word.
• Most significant bit
• Most significant bit: The leftmost bit in a RISC-V word.
• overflow
• If the number that is the proper result of such operations
cannot be represented by these rightmost hardware bits,
overflow is said to have occurred.
• Overflow
• Overflow: when the results of an operation are larger than
can be represented in a register.
2.5 Binary to decimal conversion
2.6Complements
• One's complement
• One's complement: A notation that represents the most negative
value by 10 … 000two and the most positive value by 01 … 11two,
leaving an equal number of negatives and positives but ending up
with two zeros, one positive (00 … 00two) and one negative (11 …
11two). The term is also used to mean the inversion of every bit in a
pattern: 0 to 1 and 1 to 0.
• Biased notation
• Biased notation: A notation that represents the most negative value
by 00 … 000two and the most positive value by 11 … 11two, with 0
typically having the value 10 … 00two, thereby biasing the number
such that the number plus the bias has a non-negative representation.
2.7Representing Instructions in the
Computer
•fields
•A machine instruction is composed of fields, each field having
several bits and representing some part of the instruction.
2.7 Contd
• Instruction format
• Instruction format: A form of representation of an instruction composed of fields of
binary numbers.
• Machine language
• Machine language: Binary representation used for communication within a
computer system.
• Hexadecimal
• Hexadecimal: Numbers in base 16.