In: Computer Science
In MIPS assembly language, write a function that will display the max and min value in an array. Then write a function to calculate and display the average of all values in an array. This must be done in MIPS assembly language.
MIPS Program:
$LC0:
.ascii "Maximum Element:%d\000"
$LC1:
.ascii "Minimum Element:%d\000"
display_max_and_min:
addiu $sp,$sp,-48
sw $31,44($sp)
sw $fp,40($sp)
move $fp,$sp
sw $4,48($fp)
sw $5,52($fp)
li $2,-2147483648 # 0xffffffff80000000
sw $2,24($fp)
li $2,2147418112 # 0x7fff0000
ori $2,$2,0xffff
sw $2,28($fp)
sw $0,32($fp)
b $L2
nop
$L5:
lw $2,32($fp)
nop
sll $2,$2,2
lw $3,48($fp)
nop
addu $2,$3,$2
lw $3,0($2)
lw $2,24($fp)
nop
slt $2,$3,$2
beq $2,$0,$L3
nop
lw $2,32($fp)
nop
sll $2,$2,2
lw $3,48($fp)
nop
addu $2,$3,$2
lw $2,0($2)
nop
sw $2,24($fp)
$L3:
lw $2,32($fp)
nop
sll $2,$2,2
lw $3,48($fp)
nop
addu $2,$3,$2
lw $3,0($2)
lw $2,28($fp)
nop
slt $2,$2,$3
beq $2,$0,$L4
nop
lw $2,32($fp)
nop
sll $2,$2,2
lw $3,48($fp)
nop
addu $2,$3,$2
lw $2,0($2)
nop
sw $2,28($fp)
$L4:
lw $2,32($fp)
nop
addiu $2,$2,1
sw $2,32($fp)
$L2:
lw $3,32($fp)
lw $2,52($fp)
nop
slt $2,$3,$2
bne $2,$0,$L5
nop
lw $5,28($fp)
lui $2,%hi($LC0)
addiu $4,$2,%lo($LC0)
jal printf
nop
lw $5,24($fp)
lui $2,%hi($LC1)
addiu $4,$2,%lo($LC1)
jal printf
nop
nop
move $sp,$fp
lw $31,44($sp)
lw $fp,40($sp)
addiu $sp,$sp,48
j $31
nop
$LC2:
.ascii "Average:%f\000"
display_Average:
addiu $sp,$sp,-48
sw $31,44($sp)
sw $fp,40($sp)
move $fp,$sp
sw $4,48($fp)
sw $5,52($fp)
sw $0,28($fp)
sw $0,24($fp)
b $L7
nop
$L8:
lw $2,24($fp)
nop
sll $2,$2,2
lw $3,48($fp)
nop
addu $2,$3,$2
lw $2,0($2)
lw $3,28($fp)
nop
addu $2,$3,$2
sw $2,28($fp)
lw $2,24($fp)
nop
addiu $2,$2,1
sw $2,24($fp)
$L7:
lw $3,24($fp)
lw $2,52($fp)
nop
slt $2,$3,$2
bne $2,$0,$L8
nop
lw $3,28($fp)
lw $2,52($fp)
nop
bne $2,$0,1f
div $0,$3,$2
break 7
mfhi $2
mflo $2
mtc1 $2,$f0
nop
cvt.s.w $f0,$f0
swc1 $f0,32($fp)
lwc1 $f0,32($fp)
nop
cvt.d.s $f0,$f0
mfc1 $7,$f0
mfc1 $6,$f1
lui $2,%hi($LC2)
addiu $4,$2,%lo($LC2)
jal printf
nop
nop
move $sp,$fp
lw $31,44($sp)
lw $fp,40($sp)
addiu $sp,$sp,48
j $31
nop
Program Screenshot:
Hope you understand...
if you have any doubts comment below...
plss dont dislike.....