0% found this document useful (0 votes)
28 views

Lab 10

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

Lab 10

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

Lab 10: review

Question 1:
Write a MIPS program with the following requirements:
1. Declare an array that can store 8 data elements.
2. Request integers from the user and store them into the array.
3. Check whether each element in the array is divisible by 3.
4. If an element is divisible by 3, divide it by 3.
5. If an element is not divisible by 3, change it to the number divisible by 3 that is closest
to it, i.e, if the number is 32, the result will be 33.
6. Print the final array to the terminal.
Code
.data
array: .space 32
prompt: .asciiz "Enter an integer: "
result: .asciiz "\nFinal array: "
space: .asciiz " "

.text
main:
la $t0, array
li $t1, 8

input_loop:
beq $t1, $zero, process_array
li $v0, 4
la $a0, prompt
syscall

li $v0, 5
syscall
sw $v0, 0($t0)

addi $t0, $t0, 4


addi $t1, $t1, -1
j input_loop

process_array:
la $t0, array
li $t1, 8

process_loop:
beq $t1, $zero, print_array

lw $t2, 0($t0)
rem $t3, $t2, 3
beq $t3, $zero, divisible_by_3

addi $t2, $t2, 1


rem $t3, $t2, 3
beq $t3, $zero, store

addi $t2, $t2, 1


rem $t3, $t2, 3
beq $t3, $zero, store

divisible_by_3:
div $t2, $t2, 3

store:
sw $t2, 0($t0)

addi $t0, $t0, 4


addi $t1, $t1, -1
j process_loop

print_array:
li $v0, 4
la $a0, result
syscall

la $t0, array
li $t1, 8

print_loop:
beq $t1, $zero, exit

lw $t2, 0($t0)
li $v0, 1
move $a0, $t2
syscall
li $v0, 4
la $a0, space
syscall
addi $t0, $t0, 4
addi $t1, $t1, -1
j print_loop
exit:
li $v0, 10
syscall

RESULT
Question 2:
Using the same result as question 1, write a MIPS program to find the second largest
element in a 15-elements array. If the array has more than one second largest element,
find all their indexes. Print the value and all of its indexes. For example, if the array is 1,
2, 7, 7, 3, 7, 4, 5, 6, 7, 7, 8, 8, 8, 7 the output should be Second largest value is 7, found in
index 2, 3, 5, 9, 10, 14.

.data
array: .word 3, 3, 1, 6, 6, 2, 9, 9, 3, 3, 1, 6, 6, 2, 9
prompt: .asciiz "Second largest value is "
index_prompt: .asciiz ", found in index "
comma: .asciiz ", "

.text
main:
# Step 1: Find the largest element
la $t0, array # Load base address of array into $t0
lw $t1, 0($t0) # Load the first element
li $t2, 14 # Loop counter for the rest of the elements (15-1=14)
addi $t0, $t0, 4 # Point to the next element
move $t3, $t1 # $t3 stores the largest value found

largest_loop:
beqz $t2, find_second_largest # If counter reaches 0, go to find_second_largest
lw $t4, 0($t0) # Load next element
blt $t4, $t3, skip_largest_update # If $t4 < $t3, skip
move $t3, $t4 # Update largest value

skip_largest_update:
addi $t0, $t0, 4 # Move to the next array element
addi $t2, $t2, -1 # Decrease loop counter
j largest_loop

find_second_largest:
la $t0, array # Reset base address of array
li $t2, 15 # Reset loop counter
li $t5, -2147483648 # $t5 stores the second largest value, start with smallest
possible integer
li $t6, 0 # Counter for indices

second_largest_loop:
beqz $t2, print_result # If counter reaches 0, go to print_result

lw $t4, 0($t0) # Load next element


beq $t4, $t3, skip_second_update # Skip if element is the largest

blt $t4, $t5, skip_second_update # If $t4 < $t5, skip


move $t5, $t4 # Update second largest value

skip_second_update:
addi $t0, $t0, 4 # Move to the next array element
addi $t2, $t2, -1 # Decrease loop counter
j second_largest_loop

print_result:
li $v0, 4 # Print string syscall
la $a0, prompt
syscall

li $v0, 1 # Print integer syscall


move $a0, $t5 # Print second largest value
syscall

li $v0, 4 # Print string syscall


la $a0, index_prompt
syscall

# Find and print indices of second largest element


la $t0, array # Reset base address of array
li $t2, 15 # Reset loop counter
li $t6, 0 # Reset index counter

index_loop:
beqz $t2, exit # If counter reaches 0, exit

lw $t4, 0($t0) # Load next element


bne $t4, $t5, skip_index_print # If element is not the second largest, skip

# Print the index


li $v0, 1 # Print integer syscall
move $a0, $t6 # Print index
syscall

addi $t6, $t6, 1 # Increment index counter


addi $t0, $t0, 4 # Move to the next array element
addi $t2, $t2, -1 # Decrease loop counter
j index_loop

skip_index_print:
addi $t6, $t6, 1 # Increment index counter
addi $t0, $t0, 4 # Move to the next array element
addi $t2, $t2, -1 # Decrease loop counter
j index_loop

exit:
li $v0, 10 # Exit syscall
syscall
Question 3:
Write a MIPS program to check if the elements of a 10-elements array are unique
(appears only once in the array). If there are duplicated values in the array, print those
values. For example, if the array is 1, 2, 3, 3, 3, 1, 7 ,8, 9, 10 then the output should be
Unique values: 2, 7, 8, 9, 10. Duplicated value: 2, repeated 2 times; 5, repeated 3 times.
.data
# Array size
array_size: .word 10

# Sample array (replace with your actual array data)


array: .word 1, 2, 3, 3, 3, 1, 7, 8, 9, 10
# Print strings
unique_msg: .asciiz "Unique values:"
dup_msg: .asciiz "Duplicated values:"
newline: .asciiz "\n"
space: .asciiz " "
repeated: .asciiz " repeated "
times: .asciiz " times"

# Array to store the count of duplicates


found_count: .space 40 # 10 elements x 4 bytes each

.text
main:
# Load array size
lw $t0, array_size

# Initialize the found_count array to 0


la $t6, found_count
li $t7, 0
li $t8, 10 # Number of elements in the array

init_found_count:
beq $t8, $zero, print_unique_msg
sw $t7, 0($t6)
addi $t6, $t6, 4
addi $t8, $t8, -1
j init_found_count

print_unique_msg:
# Print "Unique values:"
la $a0, unique_msg
li $v0, 4
syscall

# Outer loop counter (i)


li $t1, 0

loop1:
# Check if inner loop reached the end
beq $t1, $t0, check_duplicates # Exit if i == array_size

# Load the current element


sll $t9, $t1, 2 # t9 = i * 4 (word size)
lw $t3, array($t9)

# Reset duplicate count


li $t4, 0

# Inner loop counter (j)


li $t2, 0

loop2:
# Check if outer loop reached the end (j >= array_size)
beq $t2, $t0, update_count # Exit if j >= array_size

# Load the element to compare


sll $t5, $t2, 2 # t5 = j * 4 (word size)
lw $t6, array($t5)

# Check if elements are the same


beq $t3, $t6, increment_count

increment_j:
addi $t2, $t2, 1 # Increment outer loop counter (j++)
j loop2

increment_count:
addi $t4, $t4, 1
j increment_j

update_count:
# Store the count of duplicates in found_count array
la $t6, found_count
add $t6, $t6, $t9
sw $t4, 0($t6)

# Increment inner loop counter (i++)


addi $t1, $t1, 1
j loop1

check_duplicates:
# Print newline
la $a0, newline
li $v0, 4
syscall

# Print "Duplicated values:"


la $a0, dup_msg
li $v0, 4
syscall

# Print newline again


la $a0, newline
li $v0, 4
syscall

# Check and print duplicates


li $t1, 0

print_loop:
beq $t1, $t0, exit # Exit if i == array_size

# Load the duplicate count


sll $t9, $t1, 2 # t9 = i * 4 (word size)
la $t6, found_count
add $t6, $t6, $t9
lw $t4, 0($t6)

# If count > 1, print the value and count


blez $t4, increment_i

lw $t3, array($t9) # Load the value

# Print value
li $v0, 1
move $a0, $t3
syscall

# Print " repeated "


la $a0, repeated
li $v0, 4
syscall

# Print the count


li $v0, 1
move $a0, $t4
syscall

# Print " times"


la $a0, times
li $v0, 4
syscall

# Print newline
la $a0, newline
li $v0, 4
syscall

increment_i:
addi $t1, $t1, 1
j print_loop

exit:
# Exit program
li $v0, 10
syscall
Question 4:
Write a MIPS program that calculates and print either the volume or total surface area of
a rectangular box, cube, cylinder or rectangular pyramid. The user is able to choose
which metric, shape, and the related parameters to calculate. Note that the parameters can
be floating-point numbers.
.data
prompt_shape: .asciiz "\nChoose a shape: 1 for Rectangular Box, 2 for Cube, 3 for
Cylinder, 4 for Rectangular Pyramid: "
prompt_metric: .asciiz "\nChoose a metric: 1 for Volume, 2 for Total Surface Area: "
prompt_length: .asciiz "\nEnter the length: "
prompt_width: .asciiz "\nEnter the width: "
prompt_height: .asciiz "\nEnter the height: "
prompt_radius: .asciiz "\nEnter the radius: "
prompt_base_length: .asciiz "\nEnter the base length: "
prompt_base_width: .asciiz "\nEnter the base width: "
result_msg: .asciiz "\nThe result is: "
newline: .asciiz "\n"

.text
.globl main

# System call numbers


li_s: .word 6 # syscall for float input
li_i: .word 5 # syscall for int input
print_s: .word 2 # syscall for float output
print_i: .word 1 # syscall for int output
print_str: .word 4 # syscall for string output
exit_code: .word 10 # syscall for exit

# Functions to handle input/output


print_string:
lw $v0, print_str
syscall
jr $ra

print_float:
lw $v0, print_s
syscall
jr $ra

print_int:
lw $v0, print_i
syscall
jr $ra

read_int:
lw $v0, li_i
syscall
jr $ra

read_float:
lw $v0, li_s
syscall
jr $ra

main:
# Prompt for shape
la $a0, prompt_shape
jal print_string
jal read_int
move $t0, $v0 # $t0 stores shape choice

# Prompt for metric


la $a0, prompt_metric
jal print_string
jal read_int
move $t1, $v0 # $t1 stores metric choice

# Check shape and metric, then calculate


li $t2, 1
beq $t0, $t2, rect_box # Rectangular box
li $t2, 2
beq $t0, $t2, cube # Cube
li $t2, 3
beq $t0, $t2, cylinder # Cylinder
li $t2, 4
beq $t0, $t2, pyramid # Rectangular pyramid
j end_program # End if invalid shape

rect_box:
la $a0, prompt_length
jal print_string
jal read_float
mov.s $f0, $f0 # length in $f0

la $a0, prompt_width
jal print_string
jal read_float
mov.s $f1, $f0 # width in $f1

la $a0, prompt_height
jal print_string
jal read_float
mov.s $f2, $f0 # height in $f2

li $t2, 1
beq $t1, $t2, calc_rect_box_volume
li $t2, 2
beq $t1, $t2, calc_rect_box_surface_area

j end_program

calc_rect_box_volume:
mul.s $f3, $f0, $f1
mul.s $f4, $f3, $f2
j print_result

calc_rect_box_surface_area:
mul.s $f3, $f0, $f1
mul.s $f4, $f0, $f2
mul.s $f5, $f1, $f2
add.s $f6, $f3, $f4
add.s $f7, $f5, $f6
add.s $f4, $f7, $f7
j print_result

cube:
la $a0, prompt_length
jal print_string
jal read_float
mov.s $f0, $f0 # side length in $f0

li $t2, 1
beq $t1, $t2, calc_cube_volume
li $t2, 2
beq $t1, $t2, calc_cube_surface_area

j end_program
calc_cube_volume:
mul.s $f3, $f0, $f0
mul.s $f4, $f3, $f0
j print_result

calc_cube_surface_area:
mul.s $f3, $f0, $f0
li.s $f5, 6.0
mul.s $f4, $f3, $f5
j print_result

cylinder:
la $a0, prompt_radius
jal print_string
jal read_float
mov.s $f0, $f0 # radius in $f0

la $a0, prompt_height
jal print_string
jal read_float
mov.s $f1, $f0 # height in $f1

li $t2, 1
beq $t1, $t2, calc_cylinder_volume
li $t2, 2
beq $t1, $t2, calc_cylinder_surface_area
j end_program

calc_cylinder_volume:
li.s $f2, 3.14159
mul.s $f3, $f0, $f0
mul.s $f4, $f2, $f3
mul.s $f5, $f4, $f1
mov.s $f4, $f5
j print_result

calc_cylinder_surface_area:
li.s $f2, 3.14159
mul.s $f3, $f0, $f0
mul.s $f4, $f2, $f3
mul.s $f5, $f2, $f0
mul.s $f6, $f5, $f1
add.s $f7, $f4, $f6
add.s $f4, $f7, $f7
j print_result

pyramid:
la $a0, prompt_base_length
jal print_string
jal read_float
mov.s $f0, $f0 # base length in $f0
la $a0, prompt_base_width
jal print_string
jal read_float
mov.s $f1, $f0 # base width in $f1

la $a0, prompt_height
jal print_string
jal read_float
mov.s $f2, $f0 # height in $f2

li $t2, 1
beq $t1, $t2, calc_pyramid_volume
li $t2, 2
beq $t1, $t2, calc_pyramid_surface_area

j end_program

calc_pyramid_volume:
mul.s $f3, $f0, $f1
mul.s $f4, $f3, $f2
li.s $f5, 0.33333
mul.s $f6, $f4, $f5
mov.s $f4, $f6
j print_result
calc_pyramid_surface_area:
mul.s $f3, $f0, $f1
li.s $f5, 0.5
mul.s $f6, $f0, $f5
mul.s $f7, $f1, $f5
sqrt.s $f8, $f2
mul.s $f9, $f6, $f8
mul.s $f10, $f7, $f8
add.s $f11, $f9, $f10
add.s $f4, $f3, $f11
j print_result

print_result:
la $a0, result_msg
jal print_string

mov.s $f12, $f4


jal print_float

la $a0, newline
jal print_string

end_program:
lw $v0, exit_code
syscall
Result
Question 5:
Write a MIPS program to calculate the following integral:

.data
prompt_a: .asciiz "Enter a: "
prompt_b: .asciiz "Enter b: "
prompt_c: .asciiz "Enter c: "
prompt_d: .asciiz "Enter d: "
prompt_u: .asciiz "Enter u: "
prompt_v: .asciiz "Enter v: "
prompt_e: .asciiz "Enter e (last digit of student ID): "
result_text: .asciiz "The result of the integral is: "

.text
.globl main

main:
# Prompt user for a
li $v0, 4
la $a0, prompt_a
syscall
li $v0, 6
syscall
mov.s $f0, $f0 # a -> $f0

# Prompt user for b


li $v0, 4
la $a0, prompt_b
syscall
li $v0, 6
syscall
mov.s $f1, $f0 # b -> $f1

# Prompt user for c


li $v0, 4
la $a0, prompt_c
syscall
li $v0, 6
syscall
mov.s $f2, $f0 # c -> $f2

# Prompt user for d


li $v0, 4
la $a0, prompt_d
syscall
li $v0, 6
syscall
mov.s $f3, $f0 # d -> $f3
# Prompt user for u
li $v0, 4
la $a0, prompt_u
syscall
li $v0, 6
syscall
mov.s $f4, $f0 # u -> $f4

# Prompt user for v


li $v0, 4
la $a0, prompt_v
syscall
li $v0, 6
syscall
mov.s $f5, $f0 # v -> $f5

# Prompt user for e


li $v0, 4
la $a0, prompt_e
syscall
li $v0, 5
syscall
mtc1 $v0, $f6
cvt.s.w $f6, $f6 # e -> $f6
# Calculate e^2 (f7 = e^2)
mul.s $f7, $f6, $f6

# Compute each term for u and v


# Compute F(u)
# term1 = (a / (5 * e^2)) * u^5
li.s $f8, 5.0
mul.s $f8, $f8, $f7 # f8 = 5 * e^2
div.s $f8, $f0, $f8 # f8 = a / (5 * e^2)
mul.s $f9, $f4, $f4
mul.s $f9, $f9, $f4
mul.s $f9, $f9, $f4
mul.s $f9, $f9, $f4 # f9 = u^5
mul.s $f8, $f8, $f9 # f8 = term1

# term2 = (b / (4 * e^2)) * u^4


li.s $f10, 4.0
mul.s $f10, $f10, $f7 # f10 = 4 * e^2
div.s $f10, $f1, $f10 # f10 = b / (4 * e^2)
mul.s $f11, $f4, $f4
mul.s $f11, $f11, $f4
mul.s $f11, $f11, $f4 # f11 = u^4
mul.s $f10, $f10, $f11 # f10 = term2

# term3 = (c / (3 * e^2)) * u^3


li.s $f12, 3.0
mul.s $f12, $f12, $f7 # f12 = 3 * e^2
div.s $f12, $f2, $f12 # f12 = c / (3 * e^2)
mul.s $f13, $f4, $f4
mul.s $f13, $f13, $f4 # f13 = u^3
mul.s $f12, $f12, $f13 # f12 = term3

# term4 = (d / e^2) * u
div.s $f14, $f3, $f7 # f14 = d / e^2
mul.s $f14, $f14, $f4 # f14 = term4

# F(u) = term1 + term2 + term3 + term4


add.s $f8, $f8, $f10
add.s $f8, $f8, $f12
add.s $f8, $f8, $f14 # f8 = F(u)

# Compute F(v)
# term1 = (a / (5 * e^2)) * v^5
li.s $f9, 5.0
mul.s $f9, $f9, $f7 # f9 = 5 * e^2
div.s $f9, $f0, $f9 # f9 = a / (5 * e^2)
mul.s $f10, $f5, $f5
mul.s $f10, $f10, $f5
mul.s $f10, $f10, $f5
mul.s $f10, $f10, $f5 # f10 = v^5
mul.s $f9, $f9, $f10 # f9 = term1
# term2 = (b / (4 * e^2)) * v^4
li.s $f11, 4.0
mul.s $f11, $f11, $f7 # f11 = 4 * e^2
div.s $f11, $f1, $f11 # f11 = b / (4 * e^2)
mul.s $f12, $f5, $f5
mul.s $f12, $f12, $f5
mul.s $f12, $f12, $f5 # f12 = v^4
mul.s $f11, $f11, $f12 # f11 = term2

# term3 = (c / (3 * e^2)) * v^3


li.s $f13, 3.0
mul.s $f13, $f13, $f7 # f13 = 3 * e^2
div.s $f13, $f2, $f13 # f13 = c / (3 * e^2)
mul.s $f14, $f5, $f5
mul.s $f14, $f14, $f5 # f14 = v^3
mul.s $f13, $f13, $f14 # f13 = term3

# term4 = (d / e^2) * v
div.s $f15, $f3, $f7 # f15 = d / e^2
mul.s $f15, $f15, $f5 # f15 = term4

# F(v) = term1 + term2 + term3 + term4


add.s $f9, $f9, $f11
add.s $f9, $f9, $f13
add.s $f9, $f9, $f15 # f9 = F(v)
# Result = F(u) - F(v)
sub.s $f16, $f8, $f9

# Print result
li $v0, 4
la $a0, result_text
syscall

li $v0, 2
mov.s $f12, $f16
syscall

# Exit program
li $v0, 10
Syscall
Question 6:
In this exercise, students are required to write a recursive program although the problem
can be solved by iterations. Write a MIPS program that calculates the sum of all 10
elements in a single precision floating point array with synthetic data. Bellow is pseudo
code of the recursive version:

.data
array: .float 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 11.0
n: .word 10
result: .asciiz "Result: "

.text
.globl main

# float sum(float *v, int k)


sum:
# Prologue
addi $sp, $sp, -24 # Allocate stack space
sw $ra, 20($sp) # Save return address
sw $s0, 16($sp) # Save callee-saved register
sw $s1, 12($sp) # Save callee-saved register
sw $s2, 8($sp) # Save callee-saved register

move $s0, $a0 # $s0 = v (pointer to float array)


move $s1, $a1 # $s1 = k
# Base case: if (k == 1) return v[0]
li $t0, 1
beq $s1, $t0, base_case

# Recursive case: return v[0] + sum(&v[1], k-1)


lwc1 $f0, 0($s0) # $f0 = v[0]

addi $a0, $s0, 4 # $a0 = v + 1 (next element)


addi $a1, $s1, -1 # $a1 = k - 1

jal sum # Recursive call

mov.s $f1, $f0 # Save the result of the recursive call in $f1
lwc1 $f0, 0($s0) # Reload v[0] into $f0
add.s $f0, $f0, $f1 # $f0 = v[0] + result of sum(v + 1, k - 1)

j end # Jump to end

base_case:
lwc1 $f0, 0($s0) # Load v[0] into $f0

end:
# Epilogue
lw $ra, 20($sp) # Restore return address
lw $s0, 16($sp) # Restore callee-saved register
lw $s1, 12($sp) # Restore callee-saved register
lw $s2, 8($sp) # Restore callee-saved register
addi $sp, $sp, 24 # Deallocate stack space
jr $ra # Return

# Main function
main:
la $a0, array # Load address of the array into $a0
lw $a1, n # Load the size of the array into $a1

jal sum # Call sum function

la $a0, result
li $v0, 4
syscall

# Print the result


mov.s $f12, $f0 # Move the result to $f12 for printing
li $v0, 2 # Load syscall code for printing float
syscall # Make syscall to print float

# Exit the program


li $v0, 10 # Load exit syscall code
syscall # Make syscall to exit
Question 7:
Taking the same requirements in Question 6, write a MIPS program that is able to find
the maximum elements in an array. Bellow is pseudo code of the recursive version:

.data
array: .float 2.0, 24.1, 13.0, 4.5, 5.5, 6.7, 7.8, 8.9, 9.1, 10.0
result: .asciiz "Result: "
n: .word 10

.text
.globl main

# float max(float *v, int k)


max:
# Prologue
addi $sp, $sp, -16 # Allocate stack space
sw $ra, 12($sp) # Save return address
sw $s0, 8($sp) # Save callee-saved register
sw $s1, 4($sp) # Save callee-saved register

move $s0, $a0 # $s0 = v (pointer to float array)


move $s1, $a1 # $s1 = k

# Base case: if (k == 1) return v[0]


li $t0, 1
beq $s1, $t0, base_case

# Recursive case: max(v[0], max(&v[1], k-1))


lwc1 $f0, 0($s0) # $f0 = v[0]

addi $a0, $s0, 4 # $a0 = v + 1 (next element)


addi $a1, $s1, -1 # $a1 = k - 1

jal max # Recursive call

mov.s $f1, $f0 # Save the result of the recursive call in $f1
lwc1 $f0, 0($s0) # Reload v[0] into $f0

c.le.s $f0, $f1 # Compare v[0] and the result of the recursive call
bc1f use_f1 # If v[0] > result of recursive call, branch to use_f1
mov.s $f0, $f1 # Otherwise, $f0 = max($f0, $f1)

use_f1:
j end # Jump to end

base_case:
lwc1 $f0, 0($s0) # Load v[0] into $f0

end:
# Epilogue
lw $ra, 12($sp) # Restore return address
lw $s0, 8($sp) # Restore callee-saved register
lw $s1, 4($sp) # Restore callee-saved register
addi $sp, $sp, 16 # Deallocate stack space
jr $ra # Return

# Main function
main:
la $a0, array # Load address of the array into $a0
lw $a1, n # Load the size of the array into $a1

jal max # Call max function

# Prepare to print the result as a float with one decimal place

# Multiply by 10 to shift decimal place


li.s $f1, 10.0 # Load 10.0 into $f1
mul.s $f0, $f0, $f1 # $f0 = $f0 * 10.0
# Convert to integer to truncate to one decimal place
cvt.w.s $f2, $f0 # Convert float to integer (truncated)
mfc1 $t0, $f2 # Move integer part to $t0

# Divide to get the original integer part and the single decimal digit
li $t1, 10
div $t2, $t0, $t1 # $t2 = integer part
rem $t3, $t0, $t1 # $t3 = single decimal digit

la $a0, result
li $v0, 4
syscall

# Print integer part


move $a0, $t2
li $v0, 1 # Load syscall code for printing integer
syscall

# Print decimal point


li $a0, '.'
li $v0, 11 # Load syscall code for printing a character
syscall

# Print single decimal digit


move $a0, $t3
li $v0, 1 # Load syscall code for printing integer
syscall

# Exit the program


li $v0, 10 # Load exit syscall code
syscall # Make syscall to exit

You might also like