You are on page 1of 8

MIPS Assembly Language:

An Introduction

Paritos
h

Computer Languages:
Classification based on level of abstraction
High level languages (C, C++, Java, Python, Matlab) more closer to natural
language
You dont need to worry about the platform you are working language takes care of
memory management
Advantage: programming is easy
Disadvantage: less efficient, slower than lower level languages, sometimes code may
not work as you had intended

Low level languages (Assembly language)


Every computer architecture has its own assembly language you need to know about
the memory and computer architecture
Advantage: more efficient and faster than higher languages
Disadvantage: programming using these languages is tedious

MIPS Assembly Language


Dont confuse it with Million Instructions Per Second
For MIPS architecture
32-bit & 64-bit
High-level
language

Assembly
language

RISC
Used, mainly, in embedded systems

Machine
code

Instruction set
3 types of instructions:
R register to register
I - immediate
J jump

R type instructions
Example: addition: Sum = number_1 + number_2 (number are
stored in registers, so you are essentially adding contents of 2
registers)
Sum -> destination, number_1 -> source 1, number_2 ->source
2

Instruction set contd


I type instructions
Example: addition: $sum = number_1 + number_2 (this time
only number_1 is stored in registered, while number_2 is
provided alongwith the instruction)
Assembly instruction: addi $d, $s1, n (n is provided
immediately with instruction)

J type instructions
Example: jump: j d -> jump to address specified by d

Instruction formats
Assembly language code is translated to machine code
Machine code line consists of strings of 0s and 1s: 00010 00011
Instruction format means how the machine code is formatted
R type instruction
6 bits opcode, 5 bits for register1, 5 bits for register2, 5 bits for
destination register, 5 bits for shift amount, 6 bits for funct
I type instruction
6 bits for opcode, 5 bits for register1, 5 bits for destination register,
16 bits for immediate number
J type instruction
6 bits for opcode, 26 bits for address

Sample code
We will use MARS a MIPS simulator
Install Java if needed

Registers
One of the key advantages of assembly language is
direct control of the registers closer than higher
level languages

(Above table taken from: http://logos.cs.uic.edu/366/notes/mips%20quick


%20tutorial.htm)

You might also like