In: Computer Science
2. Maximum of three numbers:
.text
.globl main
main:
# Display prompt1
li $v0, 4
la $a0, prompt1
syscall
# read keyboard into $v0 (number x is number to test)
li $v0, 5
syscall
# move the first number from $v0 in $t0
move $t0,$v0
# Display the prmopt2 (string)
li $v0, 4
la $a0, prompt2
syscall
# read keyboard into $v0
li $v0, 5
syscall
# move the second number from $v0 in $t1
move $t1,$v0
# Display the prmopt3 (string)
li $v0, 4
la $a0, prompt3
syscall
# read keyboard into $v0
li $v0, 5
syscall
# move the third number from $v0 in $t2
move $t2,$v0
# Display the prmopt4 (string)
li $v0, 4
la $a0, prompt4
syscall
# read keyboard into $v0
li $v0, 5
syscall
# move the fourth number from $v0 in $t3
move $t3,$v0
# effectively these two lines do: $t1 = max($t0, $t1)
bge $t1, $t0, CMP2
move $t1, $t0
CMP2:
# effectively these two lines do: $t1 = max($t2, $t1)
bge $t1, $t2, L1
move $t1, $t2
# largest number in $t1
move $t2, $t0
# print answer
L1:
li $v0, 4
la $a0, answer
syscall
# print integer function call 1
# put the answer into $a0
li $v0, 1
move $a0, $t1
syscall
#exit
end: li $v0, 10
syscall
.data
prompt1:
.asciiz "Enter the first number "
prompt2:
.asciiz "Enter the second number "
prompt3:
.asciiz "Enter the third number "
prompt4:
.asciiz "Enter the fourth number "
answer:
.asciiz "The largest number is "
1. Minimum of three numbers:
.data
Msg1: .asciiz "Enter the first integer: "
Msg2: .asciiz "Enter the second integer: "
Msg3: .asciiz "Enter the third integer: "
Msg4: .asciiz "the the smallest numberis: "
.text
# Print the first message
li $v0, 4
la $a0, Msg1
syscall
# Prompt the user to enter the first integer
li $v0, 5
syscall
# Store the first integer in $t0
move $t0, $v0
# Print the second message
li $v0, 4
la $a0, Msg2
syscall
# Prompt the user to enter the second integer
li $v0, 5
syscall
# Store the first integer in $t1
move $t1, $v0
# Print the third message
li $v0, 4
la $a0, Msg3
syscall
# Prompt the user to enter the third interger
li $v0, 5
syscall
# Store the first integer in $t0
move $t2, $v0
# Determine the smallest Number
slt $s0, $t1, $t0
beq $s0, $zero, L1