Sunu2 1
Sunu2 1
the Computer
Özge ÖZTİMUR KARADAĞ
Instruction Set
• instruction : word
• Intel x86
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.
• 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:
• 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
• 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
• $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
f = (g + h) - (i + j);
• How can a computer represent and access complex data structures such as arrays and structures using 32
registers?
• 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
• Register to be loaded
• 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];
lw $t0, 8($s3)
add $s1, $s2, $t0
Words in the Memory
• 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
• Format of store:
• base register
A[12] = h + A[8]
lw $t0, 32($s3)
add $t0, $s2, $t0
sw $t0, 48($s3)
Memory - Register
• 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):
• Binary system
• Ex: (1011)2= (11)10