0% found this document useful (0 votes)
19 views7 pages

MIPS Sample Code CSC 213 by Amena Cliff

The document contains multiple MIPS assembly programs demonstrating procedure calls, calculating the lateral surface area of a cone, and using Hero's formula to find the area of a triangle. It includes data declarations for messages and constants, as well as the main logic for user input and calculations. Additionally, it features a conversion of C code to MIPS assembly for array manipulation and printing results.

Uploaded by

nelainfubara64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

MIPS Sample Code CSC 213 by Amena Cliff

The document contains multiple MIPS assembly programs demonstrating procedure calls, calculating the lateral surface area of a cone, and using Hero's formula to find the area of a triangle. It includes data declarations for messages and constants, as well as the main logic for user input and calculations. Additionally, it features a conversion of C code to MIPS assembly for array manipulation and printing results.

Uploaded by

nelainfubara64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

(1) Write a Program in Assembly MIPS illustrating the (procedure

call) function call

.data

firstMessage: .asciiz "Calling the Procedure Function now \n "


myMessage: .asciiz " \n Hello World, this is a Procedure Function Call \n
"

.text

main:

li $v0, 4

la $a0, firstMessage

syscall

j procedureToPrintHelloWorld

procedureToPrintHelloWorld:

li $v0, 4

la $a0, myMessage

syscall
(2) Program in Assembly (MIPS ) To Solve for the Lateral Surface Area of a
Cone

.data

askForRaduis: .asciiz "\n Enter the Raduis of the Cone : \n"

askForHeight: .asciiz "\n Enter the Height of the Cone : \n "

zeroAsFloat: .float 0.00

PI: .float 3.142

resultText : .asciiz "\n The Value of the Lateral Surface Area of a Cone
is : "

.text

main:
lwc1 $f10, zeroAsFloat
lwc1 $f7, PI

li $v0 4
la $a0, askForRaduis
syscall

li, $v0, 6

syscall

add.s $f1, $f10, $f0

li $v0, 4
la $a0, askForHeight
syscall

li $v0, 6
syscall

add.s $f2, $f10, $f0


mul.s $f6 , $f1, $f1

mul.s $f4, $f2, $f2

add.s $f5 , $f6, $f4

sqrt.s $f0, $f5

mul.s $f3 ,$f7, $f1

mul.s $f4, $f3, $f0

li $v0 4

la $a0 resultText

syscall

li $v0, 2

add.s $f12, $f10, $f4

syscall

(2) (b) Solve for the Area of A Triangle using Hero’s Formula

.data
askForValueA: .asciiz " \n What is the Value of a \n "
askForValueB: .asciiz "\n What is the Value of b \n "
askForValueC: .asciiz "\n What is the Value of c \n"
answerText: .asciiz "The Area of the triangle using the Hero's
Formula is : "
zeroFloat: .float 0.00
numberTwo : .float 2.00
.text

main :
lwc1 $f1, zeroFloat

lwc1 $f11 numberTwo

li $v0, 4
la $a0, askForValueA
syscall

li $v0, 6
syscall

add.s $f2, $f1, $f0

li $v0, 4
la $a0, askForValueB
syscall

li $v0, 6
syscall

add.s $f3, $f1, $f0

li $v0, 4
la $a0, askForValueC
syscall

li $v0, 6
syscall

add.s $f4, $f1, $f0

add.s $f5, $f2,$f3

add.s $f6, $f5, $f4

div.s $f10, $f6, $f11

sub.s $f7, $f10 , $f2

sub.s $f8, $f10, $f3

sub.s $f9, $f10, $f4


mul.s $f2 , $f10, $f7

mul.s $f3, $f2, $f8

mul.s $f4 , $f3, $f9

sqrt.s $f0,$f4

li $v0, 4

la $a0, answerText
syscall

li $v0,2

add.s $f12, $f1, $f0

syscall

(3) Convert C Code to MIPS Assembly Code

.data

myArray: .space 400

.text

addi $t0, $zero, 0

add $t8, $zero, 8

while :
beq $t0 4000 exit

lw $t1, myArray($t0)
mul $t1, $t1 , $t8

sw $t1 , myArray($t0)

addi $t0, $t0, 4

j while

exit:

addi $t2, $zero, 0


jal printLoop

printLoop:

beq $t2 4000 endProgram

lw $t3 myArray($t2)

li $v0 1

addi $a0, $t3 , 0

syscall

addi $t2, $t2, 4

j printLoop

endProgram:
li $v0 10
syscall

RESULT FOR NUMBER (2a)


Result for Number (2b)

You might also like