Presentation
Presented To:
Sir Najeeb Ur Rehman
Presented By:
Ali Husnain (18321519-024)
Sarab Ali (18321519-029)
Isra Mudasir (18321519-051)
Conversion of C++ Task
into Mips Code
Sorting & Searching Operations in Array
What is MIPS?
MIPS assembly language simply refers to the assembly language of the MIPS
processor. The term MIPS is an acronym for Microprocessor without
Interlocked Pipeline Stages. It is a reduced-instruction set architecture
developed by an organization called MIPS Technologies.
The MIPS assembly language is a very useful language to learn because many
embedded systems run on the MIPS processor. Knowing how to code in this
language brings a deeper understanding of how these systems operate on a
lower level.
What is SPIM? Or QtSPIM?
SPIM is a software simulator that runs programs written for MIPS
R2000/R3000 processors.
SPIM let you test and debug assemebly programs written for
MIPS.
SPIM let you see the contents of memory and registers when
programs are running ,i.e, to see what the instructions are doing.
Our Program Data Segment
.data
array: .space 40
prompt: . asciiz "Wwelcome :)Enter 10 integer values"
msg: .asciiz "Select:"
msg1: .asciiz "Press 1: Perform Searching in Array"
msg2: .asciiz "Press 2: Perform Sorting in Array"
msg3: .asciiz "Enter Your Choice:"
msg4: .asciiz "Enter Value:"
colon: .asciiz ":"
eqlmsg: .asciiz "Found"
noteqlmsg: .asciiz "Not Found"
nextline: .asciiz "\n"
spacing: .asciiz ","
findmsg: .asciiz "Enter digit which you want to find:"
sortmsg: .asciiz " Sorted values are:"
Insertion in Array
.text
main:
li $t1,10
la $a1,array //storing base address of array in pointer
loop:
addi $t1,$t1,-1
li $v0,4
la $a0,msg4 //these statements are used for message display
syscall
li $v0,5 //these statements are used for input
syscall
sw $v0,0($a1)
addi $a1,$a1,4
bnez $t1,loop
Displaying Menu in MIPS
#menu #newline
#msg printing li $v0,4
li $v0,4 la $a0,nextline
la $a0,msg syscall
syscall #printing msg
#newline li $v0,4
li $v0,4 la $a0,msg2
la $a0,nextline syscall
syscall #newline
#msg printing li $v0,4
li $v0,4 la $a0,nextline
la $a0,msg1 syscall
syscall #printing msg
li $v0,4
la $a0,msg3
syscall
Searching In Array
#getting input from user equal:
li $v0,5
li $v0,4
syscall
la $a0,eqlmsg
#Searching Will Start from here
li $t1,10 syscall
la $a1,array j nxt
loop1: noteql:
addi $t1,$t1,-1
li $v0,4
lw $t2,0($a1)
la $a0,noteqlmsg
beq $v0,$t2,equal
beq $t1,0,noteql syscall
addi $a1,$a1,4 nxt:
bne $t1,0,loop1
Sorting In Array MIPS
li $t1,9 //$t1=9 sw $t5,0($a1)
li $t2,9 //$t2=9 sw $t6,-4($a1)
la $a1,array // $a1=array; bnez $t2,lp1 // if($t2!=0)
lp1: //just a label here: // just a
label
beqz $t2,here //if($t2==0)
la $a1,array // $a1=array
addi $t2,$t2,-1 //$t2--
addi $t1,$t1,-1 //$t1--
lw $t5,0($a1)
add $t2,$t2,$t1 //$t2+=$t1
lw $t6,4($a1)
bnez $t1,lp1 //if($t!=0)
addi $a1,$a1,4 //$a1+=4
ble $t5,$t6,lp1 //if($t5<=$t6)
Printing Array
#Now Printing Sorted array #printing commas
li $t1,10 li $v0,4
#assign base address
la $a0,spacing
la $a1,array
syscall
lp:
addi $t1,$t1,-1
#checking condition
#loading value from $a1 into $t2 beq $t1,0,end1
lw $t2,0($a1) #moving to next element
#Printing Value addi $a1,$a1,4
move $a0,$t2
j lp
li $v0,1
end1:
syscall