0% found this document useful (0 votes)
29 views28 pages

Sunu2 1

The document discusses the key components of an instruction set architecture including instructions, registers, memory, and different operand types. It provides examples of how high-level code is compiled to low-level MIPS assembly instructions using registers, loads/stores for memory access, and immediate operands for constants. The goal is to design an instruction set that balances simplicity, performance, and efficiency across both hardware and software.

Uploaded by

garamanli707
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views28 pages

Sunu2 1

The document discusses the key components of an instruction set architecture including instructions, registers, memory, and different operand types. It provides examples of how high-level code is compiled to low-level MIPS assembly instructions using registers, loads/stores for memory access, and immediate operands for constants. The goal is to design an instruction set that balances simplicity, performance, and efficiency across both hardware and software.

Uploaded by

garamanli707
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Instructions : Language of

the Computer
Özge ÖZTİMUR KARADAĞ
Instruction Set

• instruction : word

• instruction set: vocabulary

• Similarity among programming languages

• MIPS (till 1980)

• ARMv7 (similar to MIPS )

• Intel x86

• ARMv8 (increases adress size of ARMV7 from 32 bits to 64 bits, more


similar to MIPS rather than ARMv7 :))
Properties of Instruction Sets
• Common goal of hardware designers is to find a language that makes
it easy to build the hardware and the compiler while maximizing
performance and minimizing cost and energy.

• 1947`deki şu söylem bugün aynen geçerlidir:


It is easy to see by formal-logical methods that there exist certain [instruction sets] that are in abstract adequate to control and cause the

execution of any sequence of operations . . . . The really decisive considerations from the present point of view, in selecting an [instruction set], are

more of a practical nature: simplicity of the equipment demanded by the [instruction set], and the clarity of its application to the actually

important problems together with the speed of its handling of those problems.

Burks, Goldstine, and von Neumann, 1947


Instruction Set
Hardware & Software
• We will introduce an instruction set which follows the ‘simplicity in
equipment’ principle.

• We will see how the instruction set is:


• represented in the hardware
• Converted from a high level programming language to low level instructions.
Operations of the Computer Hardware

• All computers perform arithmetic operations.

• The MIPS assembly language notation for adding two variables (b,c) and puttig the result to a is;

• add a, b, c

• In this notation:

• All instructions perform only one operation

• All intructions have thee variables.

• Ex: operation a=b+c+d+e :

• add a, b, c # sum of b and c is placed in a

• add a, a, d # sum of b, c and d is placed in a

• add a, a, e # sum of b, c, d and e is placed in a


MIPS

• Unlike other programming languages:


• Each line contains only one instruction
• Comments terminate at the end of the line.
1st Design Rule

• Simplicity favors regularity.:


• All instructions have exactly three variables.
• It is always simpler to work with a constant number of variables than to work with a
varying number of variables in terms of the hardware.
Example 1

• A program in C language is converted to a MIPS code by the


compiler.

• Convert the following piece of C programs into equivalent MIPS


codes:

• 1. a = b + c; add a, b, c
d = a - e; sub d, a, e

add t0, g, h
• 2. f = (g +h) - (i+j); add t1, i, j
sub f, t0, t1
Operands of the Computer Hardware

• The operands of arithmetic instructions are restricted; they must be from a limited
number of special locations built directly in hardware called registers.
• Registers are primitives used in hardware design that are also visible to the
programmer.
• The size of a register in the MIPS architecture is 32 bits.
• Groups of 32 bits occur so frequently that they are given the name word in the
MIPS architecture..
• One major difference between the variables of a programming language and
registers is the limited number of registers, typically 32 on current computers, like
MIPS.
• The three operands of MIPS arithmetic instructions must each be chosen from one
of the 32 32-bit registers.
2nd Design Principle

• Why is the number of registers restricted?

• Smaller is faster.
• A very large number of registers may increase the clock cycle time simply because it
takes electronic signals longer when they must travel farther.
• 31 registers may not be faster than 32. Yet, the truth behind such observations
causes computer designers to take them seriously. In this case, the designer must
balance the craving of programs for more registers with the designer’s desire to keep
the clock cycle fast.
• Another reason for not using more than 32 is the number of bits it would take in the
instruction format.
Registers in MIPS

• Registers are represented by two characters that follow a $ symbol:

• $s0, $s1, … (registers that are used for the variables in high level
programming language such as C and Java)
• $t0, $t1, … (temporary registers that are used for compiling MIPS instructions)
Example

• Compiling a C assignment Using Registers:


• It is the compiler’s job to associate program variables with registers.

• The variables f, g, h, i, and j are assigned to the registers $s0, $s1,


$s2,$s3, and $s4, respectively. What is the compiled MIPS code?

f = (g + h) - (i + j);

add $t0, $s1, $s2


add $t1, $s3, $s4
sub $s0, $t0, $t1
Memory Operands

• How can a computer represent and access complex data structures such as arrays and structures using 32
registers?

• Remember the five classic components of computer.

• When the registers are not enough, memory is employed.

• Arithmetic operations occur only on registers in MIPS instructions; thus, MIPS must include instructions that
transfer data between memory and registers. Such instructions are called data transfer instructions.

• To access a word in memory, the instruction must supply the memory address.

• Memory is just a large, single-dimensional array, with the address acting as the index to that array, starting at
0.
Five Classic Components of the Computer

• Input
• Output
• Memory
• Control + Datapath = Processor
Memory Operands

• Th e data transfer instruction that copies data from memory to a


register is traditionally called load.
• Format of load:

• Name of the operation

• Register to be loaded

• a constant and register used to access memory. (The sum of


the constant portion of the instruction and the contents of the second
register forms the memory address)

• The name of this instruction in MIPS is lw (load word).


Example

• 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];

• we must first transfer A[8] to a register. The address of this array


element is the sum of the base of the array A, found in register $s3,
plus the number to select element 8.

lw $t0, 8($s3)
add $s1, $s2, $t0
Words in the Memory

• In addition to associating variables with registers, the compiler allocates data


structures like arrays and structures to locations in memory. The compiler can then
place the proper starting address into the data transfer instructions.
• Since 8-bit bytes are useful in many programs, virtually all architectures today address
individual bytes. Therefore, the address of a word matches the address of one of the 4
bytes within the word, and addresses of sequential words differ by 4:

• In MIPS, words must start at addresses that are multiples of 4. This requirement is
called an alignment restriction, and many architectures have it.
Word Addressing

• `Big end`: use the address of the left most for accessing a word
• `Little end`: use the address of the rightmost for accessing a word.
• MIPS is in the `big end` group.
• Byte addressing also affects the array index.
• The off set to be added to the base register $s3 must be 4 x 8, or 32,
so that the load address will select A[8] and not A[8/4].
Operands in Memory

• Instruction that copies data from register to memory is store.

• Format of store:

• Name of the operation

• The register to be stored

• off set to select the array element

• base register

• The name of this instruction in MIPS is sw (store word).


Compiling Using Load and Store
• 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]

lw $t0, 32($s3)
add $t0, $s2, $t0
sw $t0, 48($s3)
Memory - Register

• Many programs have more variables than computers have registers.


Consequently, the compiler tries to keep the most frequently used variables in
registers and places the rest in memory, using loads and stores to move
variables between registers and memory.
• The process of putting less commonly used variables (or those needed later)
into memory is called spilling registers.
• The hardware principle relating size and speed suggests that memory must be
slower than registers, since there are fewer registers. This is indeed the case;
data accesses are faster if data is in registers instead of memory.
• Registers take less time to access and have higher throughput than memory.
• To achieve highest performance and conserve energy, an instruction set
architecture must have a sufficient number of registers, and compilers must use
registers efficiently.
Constant or Immediate Operands

• Many times a program will use a constant in an operation—


• ie. incrementing an index to point to the next element of an array

• For example, to add the constant 4 to register $s3 assuming 4 is stored in memory
location $s1+AddrConstant, we could use the code
lw $t0, AddrConstant4($s1)
add $s3, $s3, $t0

• An alternative that avoids the load instruction is to offer versions of the arithmetic
instructions in which one operand is a constant.
• Addi (add immediate):

addi $s3, $s3, 4

• Zero simplifies instruction set by offering useful variations:


• For example, the move operation is just an add instruction where one operand is zero.
• Register $zero always has value zero.
Signed and Unsigned Numbers

• Binary system
• Ex: (1011)2= (11)10

• Least significant bit – rightmost


• Most significant bit – leftmost

• How many different numbers can be stored in an 32 bit register?

• These nubers are unsigned numbers.


Negative Numbers

• A sign bit can be used – sign magnitude representation


• Where will the sign bit be?
• How will 0 be represented?
• 2’s complement representation

• In 2’s complement representation the leftmost bit is 1 in negative numbers


and it is 0 in positive numbers. This bit is also referred as sign bit.
Conversion from Binary to Decimal

• What is the decimal equivalent of the following number in 2’s


complement form?
• (1111 1111 1111 1111 1111 1111 1111 1100)2
Practical Method for 2’s Complement

• Convert 0s to 1s and 1s to 0s and add 1


Sign Extension

• Representation of a n bit number with more than n bits:


• For example representing a 16 bit number in 32 bits:
• Take the most significant bit
• Copy that bit to the initial bits of the register.
• Copy the number to the right bits of the register.
• This operation is referred as sign extension.

• Ex: Convert 16 bit long 210 to 32 bits.


Sign Extension

• Ex: Convert 16 bits long -210 to 32 bits.

You might also like