LANGUAGE OF THE COMPUTER
Introduction to MIPS
-Microprocessor
without Interlocked Pipeline Stages as known as MIPS is a
reduced instruction set computer (RISC) instruction set architecture.
-MIPS always refers
to assembly language that are registers. Register are limited number of special
location built directly into the hardware to performed operation givens.
-MIPS
processors are divided into three part
·
Text segment – holds the machine language code for
instruction in source file(user program)
·
Data segment – holds the data that the program operates on.
It is divided into two parts
o Static data - contains
statically allocated whose size does not change as the program access them.
o Dynamic data – this data
allocated and deallocated by the programs executed
·
Stack segment – its resides at the top of user address space.
In a high level language programs, local variables and parameter are pushed and
popped on the stack as operating system expands and shrinks the stack segment
towards the data segment.
MIPS ASSEMBLY LANGUAGE PROGRAM
FORMAT.
-
MIPS assembler languages is a plain text file that were made
up of two types statement
o Assembler directive that
tells the assembler on how to translate a program but cannot be translated into
machine code.
o Executable instruction
where upon execution will be translated into machine code. Sometimes can be
referred as program code.
-
MIPS program have a format that comprises four column
Label
|
Opcode
|
Operand
|
#comment
|
Sll , $0 , $0 , $0
READING MIPS CODE
- MIPS code must be read or refer the core instruction set to
identify the properties of the operation
given.
o Example of the MIPS code
from high level language that are translated
§ 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
§ add t0, g, h # temp t0 = g
+ h,
add t1, i, j # temp t1 = i
+ j,
sub f, t0, t1 # f = t0 - t1.
o Example of the MIPS code
using register
§ add $t0, $s1, $s2
add $t1, $s3, $s4
sub $s0, $t0, $t1
§ lw $t0, 32($s3)
add $t0, $s2, $t0
sw
$t0, 48($s3)
o R-type format
31 26 25 21 20 16 15 11 10 6 5 0
MIPS BASIC FORMAT INSTRUCTION
o R-type format
Opcode
(6bits)
|
Rs
(5bits)
|
Rt
(5bits)
|
Rd
(5bits)
|
Shamt
(5bits)
|
Funct
(6bits)
|
o I-type format
Opcode
(6bits)
|
Rs
(5bits)
|
Rt
(5bits)
|
Immediate
(16bits)
|
31 26 25 2120 16 15 0
o J-type format
Opcode
(6bits)
|
Address
(26bits)
|
31 26 25 0
Instruction fields
-
rs: first source register number
- rt: second source register number
- rd: destination register number
- shamt: shift amount (00000 for now)
- funct: function code (extends opcode)
Identify the format of the MIPS code
- rt: second source register number
- rd: destination register number
- shamt: shift amount (00000 for now)
- funct: function code (extends opcode)
Identify the format of the MIPS code
-to identify the format of the mips code is
based on the operation given by referring the core
instruction set below
instruction set below
-
Example:
§ add $t0, $t1, $t2 – is a R-format
§ lw $t1, 4($t2) – is a I-format
In MIPS, its has several addressing modes. Addressing modes are the ways of specifying an operand or a memory address. The MIPS addressing modes have five types which are:
- Register Addressing.
- Immediate Addressing.
- PC-Relative Addressing.
- Base Addressing.
- Pseudo-direct Addressing.
Now, let me explain one-by-one about the addressing.
- Register addressing.
-Simplest addressing modes.
-Both operand are in a register.
-Instruction will be executed faster in comparison with other addressing modes because its do not involves with memory access.
Example:
add $t0, $t1, $t2
where $t0 = rd
$t1 = rs
$t1 = rs
$t2 = rt
Thus: $t0=$t1+$t2.
- Immediate Addressing.
- Operand is a constant within the encoded instruction.
- Instruction will be executed faster because does not involve memory access but the size of operand is limited to 16 bits.
Example:
addi $t1, $t1, 1
where $t1 = rd
$t1 = r1
1 = immmediate value
1 = immmediate value
Thus: $t1 = $t1 + $1
- Base Addressing.
- Also known as indirect addressing.
- Register act as a pointer to an operand located at the memory location whose address is in the register.
- The register is called a base.
- The address of the operand is the sum of the offset value and the base value(rs). The size of operand are limited to 16 bits because each MIPS instruction fits into a word.
-The offset value is a signed number which is represented in a two's complement format. Therefore, offset value can also be a negative number.
Example:
lw $t1, 4($t2)
where $t1 = rs
$t2 = base (memory address)
4 = offset value
Thus: $t1 = Memory [$t2 + 4]
if lw $t1, -4($t2)
Thus: $t1 = Memory [$t2 - 4]
- PC-Relative Addressing.
-Used in conditional branches.
- The offset value can be an immediate value or an interpreted label value.
-The effective address is the sum of the Program Counter (PC) and offset value in the instruction. The effective address determines the branch target.
Example:
beqz $t0.strEnd
where $t0 = rs
100 = offset
100 = offset
Thus: if ($t1 == 0) goto PC + 4 + (4*2)
- Pseudo- Direct Addressing
-Specially used for J-type instruction, j and jal.
-The effective address is calculated by taking the upper 4 bits of the PC and concatenated to the 26 bits immediate value, and the lower bits are 00.


No comments:
Post a Comment