You are on page 1of 15

Pseudo code Development

Lec 8 MIPS
Instructor: Ms. Amna K
Develop the Algorithm in Pseudocode
• In a language such as Pascal, C, C++, or JAVA programmers use descriptive
variable names such as: speed, volume, size, count, amount, etc.
• Variable names correspond to memory locations, and the values stored in these
memory locations
• A compiler will attempt to develop code in such a way as to keep the variables
that are referenced most often in processor registers, because access to a variable
in a processor register is faster than access to random access memory (RAM).
• MIPS has 32 processor registers. In the case of the MIPS architecture, all of the
data manipulation instructions and the control instructions require that their
operands be in the register file.
• For example,
– $t0 corresponding to speed,
– a value in register $t1 corresponding to volume,
– a value in register $t2 corresponding to size,
Continue….
• . Descriptive variable names will usually appear only
in the Load Address (la) instruction where there is a
reference to a symbolic memory address.
• In assembly language we define and allocate space
for variables in the data segment of memory using
assembler directives such as “.word” and “.space”.
• Strings are allocated space in memory using the
assembler directive “.asciiz”.
Translate C into MIPS
C/C++ MIPS
• int t1=10, t2=3; • li $t1, 10
• int t3=t1+2*t2 • li $t2, 3
• sll $t2, $t2, 1
• add $t3, $t2, $t1
Translate MIPS into C/C++
MIPS C/C++
• li $s0, 2 • int s0=2, s1=6, t0=2;
• li $s1, 6 • int s2 = s1 + s0;
• li $t0, 2 • s2 *= 8;
• add $s2, $s1, $s0 • int s3 = s2 * t0;
• sll $s2, $s2, 3
• mult $s2, $t0
• mflo $s3
Program 1: Hello World!
.data
message: .asciiz “HELLO WORLD \n”
.text
li $v0, 4
la $a0, message
syscall
Program 2: Printing a character
.data
myCharacter: .byte ‘z’
.text
li $v0, 4
la $a0, myCharacter
syscall
Program 3: Multiply using shift left logical

.data

.text
addi $t0, $zero, 4
Sll $t0, $s0, 2

#print it;

li $v0, 1
add $a0, $zero, $t0
syscall
Program 4: Multiply using MULT
.data

.text
addi $t0, $zero, 2000
addi $t1, $zero, 10

mult $t0, $t1


mflo $s0

#display the product to the screen;

li $v0, 1
add $a0, $zero, $s0
syscall
Program 5: Multiply using MUL
.data

.text
addi $s0, $zero, 10
addi $s1, $zero, 4

mul $t0, $s0, $s1

#display the product to the screen;

li $v0, 1
add $a0, $zer0, $t0
syscall
Program 6: Divide through DIV
.data

.text
addi $t0, $zero, 30
addi $t1, $zero, 6

div $to, $t1

mflo $s0 # qoutient


mfho $s1# remainder

#display the product to the screen;

li $v0, 1
add $a0, $zero, $s0
syscall
Program 7: Divide through DIV
.data

.text
addi $t0, $zero, 30
addi $t1, $zero, 5

div $s0, $to, $t1

#display the product to the screen;

li $v0, 1
add $a0, $zero, $s0
syscall
Program 8: C Pseudo code to MIPS
.# Functional Description:
# A program to find the Sum of the Integers from 1 to N, where N is a value # input from the
keyboard. ################################################################## #
Pseudocode description of algorithm:
# main: cout << “Please input a value for N”
# cin >> v0
# If ( v0 <= 0 ) stop
# t0 = 0;
# While (v0 > 0 ) do
#{
# t0 = t0 + v0;
# v0 = v0 - 1;
#}
# cout << t0;
# go to main
MIPS Code:
15

You might also like