0% found this document useful (0 votes)
5 views

Lecture # 02

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lecture # 02

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Instructions:

The Language of the


Computer
Lecture # 02
Computer Organization and Assembly Language
Computer Instructions
• What are the instructions?
• The commands that tell a computer what to do.
• The instructions are written in a programming language, which is a language
that a computer can understand.
• What is instruction set?
• An instruction set is also known as an instruction set architecture (ISA)
• It is a set of commands that a processor can understand and execute
• These instructions tell the processor what operations to perform, such as
arithmetic, data manipulation, and input/output operations
• What is specific purpose of ISA?
• The ISA acts as an interface between the hardware and the software, specifying
both what the processor is capable of doing as well as how it gets done.
• How many ISA we have?
• Common ISAs include x86, ARM, PowerPC, RISC-V and MIPS
Why MIPS Instruction Set?
• In this course, we will focus on MIPS architecture and
why?
• Its is an elegant example of the instruction sets designed
since the 1980s.
Feature MIPS ARM x86 RISC-V

Moderately
Complexity Simpler More Complex Most Complex
Complex

Open Source Yes Less Open Closed Source Open Source

Focus on
Strong Moderate Weak Moderate
Concepts

Documentatio
Extensive Good Moderate Growing
n
Why MIPS Instruction Set? (Contd.)
• Why MIPS is often chosen as a base for studying computer
architecture over ARM, x86, or RISC-V?
• Simplicity
• MIPS has a simple and regular instruction set architecture (ISA)
• Easier for students to understand the fundamental concepts of computer architecture,
like pipelining, caching, and hazard detection
• Its clean design allows focusing on core concepts without the complexities of legacy
architectures like x86.
• Open Source
• Its open-source license
• Freely available tools and simulators are crucial for hands-on learning
• Focus on Concepts
• Unlike x86 which has grown complex over time due to backward compatibility, MIPS
offers a clean separation between core concepts and implementation details
• Well-Documented
• MIPS has extensive and well-maintained documentation, making it easier for students
to learn about the architecture and its features
Operations of the Computer
Hardware
• Every computer must be able to perform arithmetic.
• For Example, the MIPS assembly language notation
add a, b, c
It instructs the computer to add the two variables b and c and to put their sum in a
• How many operations can be performed in single MIPS instruction?
• Each MIPS arithmetic instruction performs only one operation and must
always have exactly three variables.
• For example, a = b+c+d+e follows the sequence as given below:
• add a, b, c # The sum of b and c is placed in a
• add a, a, d # The sum of b, c, and d is now in a
• add a, a, e # The sum of b, c, d, and e is now in a
• Thus, it takes three instructions to sum the four variables.
Operands of the Computer
Hardware
• Where are operands in Assembly language?
• Operands of arithmetic instructions are in limited number of
special locations in hardware and called registers
• What are registers?
• Registers are high-speed temporary storage units built
directly into the central processing unit (CPU)
• They act as the CPU's immediate workspace, holding data
and instructions that are currently being processed
• What is the size of MIPS registers?
• The size of a register in the MIPS architecture is 32 bits
Operands of the Computer
Hardware
Variable in Programming vs
Registers
• Variables in Programming Languages
• Variables are named storage locations in a program's memory
• The programmer creates variables to store data that the program will
use during its execution
• In theory, a programming language can allow for an unlimited
number of variables, as long as there's enough memory available to
store them.
• Registers
• Registers are part of the CPU and serve as the CPU's immediate
workspace
• They store data and instructions that are currently being processed
• There are a limited number of registers, typically 32 in MIPS
processors.
Operands of the Computer
Hardware
• What is number of registers are increased?
• A very large number of registers may increase the clock cycle
time. Because
• Signal Propagation Delay
• Electronic signals take time to travel within a circuit. With a very large
number of registers, the distance that signals need to travel to access
specific registers increases. This can lead to a delay in accessing and
manipulating data in those registers.
• Decoder Complexity
• The CPU needs circuitry to decode instructions and determine which
register holds the required data.
• With a large number of registers, this decoding logic becomes more
complex, potentially slowing down the entire process.
Operands of the Computer
Hardware
• How are registered names in MIPS?
• MIPS convention is to use two-character names following a
dollar sign to represent a register
• $s0, $s1, . . . for registers that correspond to variables in C
• $t0, $t1, . . . for temporary registers needed to compile the
program
Example:
Example
Memory Operands
• Programming languages have simple variables that contain
single data elements char, int, float, bool.
• But there are complex data structures—arrays and
structures
• These complex data structures can contain many more data
elements than there are registers in a computer
• How can a computer represent and access such large
structures?
• The processor can keep only a small amount of data in registers
• But computer memory contains billions of data elements
• Hence, data structures (arrays and structures) are kept in memory
Memory Operands
• In MIPS, arithmetic operations occur only on registers
• But which instructions exchange data between memory
and registers?
• Instructions that transfer data between memory and registers
are called data transfer instructions
• To access a word in memory, the instruction must
supply the memory address
• What is memory address?
• Memory is just a large, single-dimensional array, with the
address acting as the index to that array, starting at 0.
Memory Operands
• The address of the third data element is 2
• The value of Memory [2] is 10
Memory Operands
Memory Operands: Load Word
instruction
• What instruction is used to copy data from memery to a
register?
• Data transfer instruction that copies data from memory to a
register is called lw load word instruction
• It load a word (4 bytes) of data from memory into a register
• Syntax
lw rt, offset(rs)
• rt: specifies the destination register where the loaded word will be stored
• offset: This is a signed 16-bit integer that represents the memory address
relative to the base register (rs).
• rs: specifies the base register that holds the starting memory address. The
data will be loaded from address(rs) + offset.
Example: lw Instruction
• Let’s assume that A is an array of 100 words and that
the compiler has associated the variables g and h with
the registers $s1 and $s2 as before.
Let’s also assume that the starting address, or base
address, of the array is in $s3.
• Compile this C assignment statement:
g = h + A[8];
Example: lw Instruction (Contd.)
• One of the operands is in memory which is A[8]
• We must first transfer A[8] to a register because add instruction works on
two registers add dest, src1, src2
lw $t0,8($s3) # Temporary reg $t0 gets A[8]
• What is destination register?
• rt: the destination register is $t0,8
• What is offset?
• 8
• What is base register?
• rs: specifies the base register $s3, represents Array A
• ADD can operate on $t0 (which equals A[8]) and $S2
add $s1,$s2,$t0 # g = h + A[8]
• Then store the sum in the register $s1
Memory Operand
• For arrays and structures, which address is stored in register?
• Starting address of the arrays and structures into the register using the data transfer
instructions.
• What is meant by word in computer architecture?
• A word is a larger unit of data storage, typically consisting of 4 bytes (32 bits) in many
architectures, including MIPS.
• What is byte addressable memory?
• The CPU can access and manipulate individual bytes of data in memory
• What is word addressable memory?
• The CPU can access and manipulate individual words in memory as show in Figure 2.3
• Can the CPU access individual bytes if its word addressable memory?
• If a word address is specified (e.g., the starting address of a word), that address
actually corresponds to the memory location of one of the 4 bytes within that word
• This is because the byte-addressable memory allows you to access any of those 4
bytes individually using slight variations of the word address
Memory Operand
• What is endianness in computer architecture?
• The order in which bytes are arranged to form a multi-byte
data type (like a word) in memory. There are two main
conventions: Big-Endian and Litter Endian
• What is Big-Endian?
• The most significant byte (MSB) of the data is stored at the
lowest memory address. MIPS architecture is indeed big-
endian.
• What is Little-Endian?
• The least significant byte (LSB) of the data is stored at the
lowest memory address.
Memory Operand: Store Word
• What is a store word instruction:
• The instruction to copies data from a register to memory is called store word
instruction
• Its denoted by sw, and is used to store a word (4 bytes) of data from a register
into memory
sw rt, offset(rs)
• rt:
• specifies the source register that holds the word (4 bytes) of data to be stored.
• rt can be any of the general-purpose registers in MIPS
• Offset
• This is a signed 16-bit integer that represents the memory address relative to the base
register (rs)
• Rs
• specifies the base register that holds the starting memory address
• The data will be stored at address(rs) + offset.
Example: Store Word Instruction
• Assume variable h is associated with register $s2 and
the base address of the array A is in $s3
• What is the MIPS assembly code for the C assignment
statement below?
A[12] = h + A[8];
Example: Store Word Instruction
• First load data from A[12] into $t0
lw $t0,32($s3) # Temporary reg $t0 gets A[8]
Important Difference: This time we use the proper offset for byte addressing in the load
word instruction to select A[8]
• Seconldy, add h and $t0
add $t0,$s2,$t0 # Temporary reg $t0 gets h + A[8]
• Third, stores the sum into A[12], using 48 (4 *12) as the
offset and register $s3 as the base register.
sw $t0,48($s3) # Stores h + A[8] back into A[12]

You might also like