Blogger Templates

Sunday 16 December 2012

MIPS

MIPS

1.      Organization of a computer
2.      Microprocessor operations
3.      Introduction to MIPS
4.      Data Representation
5.      Fundamentals of emulation

1.ORGANIZATION OF A COMPUTER

·         The most basic components of a computer are input, output, memory, datapath (old term are ALU) and control with system bus acting as communication channel for every components.

·         Organization of a Microprocessor




i)Datapath-called as (ALU) performing arithmetic operations.
ii)Control-a processor component sending signals (determine operations of the component).
iii)Memory-area where programs are stored when running and containing data needed by running program.
iv)Input-devices that writes data to memory.
v)Output-devices that reads data from memory and convey/showcase result of computation.

·         Datapath and control unit is found in the CPU.
·         Memory usually refers to main memory(RAM).
·         Input and output are also devices that manipulates data to or from memory.   

    2.MICROPROCESSOR OPERATIONS

·         Usually a processor executes are machine instructions consisting of three basic steps.The process of completing these three steps is called machine cycle.
·         Machine cycle


·         First,instruction starts after program counter supply instruction address to the instruction memory.Then,register operands used by an instruction are specified by fields of that instruction (after the instruction is fetched).Next, the register operands is fetched.Finally,the operation stated in machine instruction is performed.

    Written by Ng Wui Sheng

Introduction to MIPS

MIPS – MICROCOMPUTER WITHOUT INTERLOCKED PIPELINE STAGES
- Maximize performance/minimize cost/reduce design time
- Is a reduced instruction set computer (RISC) instruction set architecture(ISA) developed by MIPS technologies.
- (ISA) defines the interface between user and microprocessor/ is a part of the computer architecture related to programming.
- (ISA) includes instruction set, rules for using instructions and instruction encoding.
- It is basically a language of the machine much more primitive than higher level language. It has no sophisticated control flow such as while or for loops such as we learn in programming
- It is a type of architecture consisting of instruction at which is reduced to enable maximum performance


Architecture of MIPS R2000




Memory Layout, MIPS




-Based on (figure), system using MIPS processors typically divide memory into three segments.

i) Text segment – holds machine language code for instructions in the source file or input program (user program).

ii) Data segment – holds data that the program is operating on Divided into two parts.
1)      Static data- containing data allocated statically which size does not change when accessed by program.
2)      Dynamic data- containing data allocated and deallocated as program executes.
       
iii) Stack segment –For function and procedure linkage, the bottom of the stack is at 0x7FFFFFFF and grows toward the data segment.

Data Alignment
MIPS Data Size
Type
Size (Binary)
Size (Hexadecimal)
Byte
8 bits(11011101)
2 Hexa (AB)
Word
4 bytes, 32 bits
8 Hexa
Double Word
8 bytes, 64 bits
16 Hexa

Data Alignment
Double Word
Word
Word
Half word
Half word
Half word
Half word
Byte
Byte
Byte
Byte
Byte
Byte
Byte
Byte


Written By Mohd Safar
Registers
i) MIPS contains 32 general registers numbered 0-31(register =$).

ii) Registers $0 always contains value 0, and is the register numbered $0.

iii) Registers reserved for assembler and operating system are $at($1), $k0($26) and $k1($27) and should not be used by user programs or assembler.

iv) Registers $a0-$a3($4-$7) are use to pass the first four arguments to routines

v) Registers $v0 and $v1 ($2 and $3) are used to return values from function.

vi) Registers ($t0- $t9) which is ($8-$15,$24,$25) are caller saved registers that are used to hold temporary values. (Beginners are advised to use these registers in their program.)

- Registers $s0-$s7($16-$23) are called saved registers that holds values preserved across call functions such as a value entered by user.
- Register $gp ($28) is a global pointer pointing to the middle of a 64k block of memory in the static data segment. (gp = global pointer)
-Register $sp ($29) is the stack pointer, pointing to the last location of the stack.  (sp= stack pointer)
- Register $fp($30) is the frame pointer.
-Register $ra($31) contains return address written by instructions.




Trap register by SPIM to handle certain tasks such as handling exception
-On top is PC
-2nd(14)EPC-address of instruction that causes exception.
-3rd(13)Cause-exception type and pending interrupt bits.
-4th(8)BadVAddr-memory address at which address exception occurred.
-5th(12)status-interrupt mash and enable bits.


System calls

-SPIM simulator provides an exception handler that simulates a tiny OS that does input from keyboard and output to the monitor.Assembly program request a service by landing the System Call(syscall) instructions.
-System call functions.


Service
Print_int
Print_float
Print_double
Print_string
read_int
read_float
read_double
read_string
sbrk(allocate memory)
exit
Print_char
read_char
System call code
1
2
3
4
5
6
7
8
9
10
11
12
Argument
$a0=integer
$f12=float
$f12=double
$a0=string



$a0=buffer,$a1=Length
$a0=amount

$a0=char
Result




$v0=integer
$f0=float
$f0=double

$v0=address


$v0=char



System call code starts with li(load instructions),$v0($2) and system call code
such as
             (li $v0,4) # system call code for print string
             (syscall) # return control

MIPS Assembly Language Program Format

-MIPS assembler program is a plain text file made up of
i) assembler directive telling assembler how to translate a program but it cannot be                      translated to machine code/language.
ii) executable instructions where upon execution will be translated into machine language or program code.
-MIPS program have 4 columns format.
Format e.g.

Label
main:
Opcode
li
Operand
$v0,4
Comment
#system call code for print string
i)                    Label is optional/used to mark specific points in program code.
ii)                  OPCODE denotes basic operations and format of an instruction.
iii)                OPERAND contains registers,shamt,labels to jumps into and constant/address.
iv)                OPCODE and OPERAND can found in MIPS green sheet.
v)                  COMMENT starts with # and helps programmer to understand the program.

Written by Soo Pheng Kian

4.DATA REPRESENTATION




a)Character Representation
-A character be represented by one byte(8 bit).
-ASCII is a standard for character represented used to represent characters.
-Assembler actually assemble or arrange ASCII bit patterns in hexadecimal form that you have asked to be placed in memory.The analogy is assembler changes your data into binary or hexadecimal form to be stored in memory according to the table below(ASCII table).

b)Number Representation
-Computer operates on binary system,however MIPS number is represented as decimal or hexadecimal or hexadecimal number system.

5.FUNDAMENTALS OF EMULATION

-Emulator (imitator)


-To learn MIPS architecture,emulator is used to understand how the processor works.

-An emulator is often used for debugging working with emulator is much more convenient.

-First,to create an object module[contains bit patterns (ASCII character) produced by the   assembler, you must write assembly source code/language and debug it through the assembler.


-An example of MIPS processor emulator is QtSpim which is a freeware and can be downloaded  easily in SourceForge.com to better understand MIPS processor architecture.


Written by Andy Low Fu Hwa

No comments:

Post a Comment