Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MIPS assembly language program to do the following. Do not use any pseud

ID: 3751303 • Letter: W

Question

Write a MIPS assembly language program to do the following. Do not use any pseudo or extended 1. 2. Print your name Using a bottom testing loop, prompt the user to enter a number from 1 to 5. If the number entered is not in the range from 1 to 5, print an error message. Your program should continue to prompt for and read input until a value from 1 to 5 is entered. Once the number is 1 to 5, then using a top testing loop, repeat the following the number of times that you finally got in the range from 1 to 5. 3. a. Prompt for and read two integers. b. Print the absolute value of the difference of the numbers. c. If the first integer is less than or equal to the second integer, print the sum of the integers from the first integer THROUGH the second integer. Otherwise if the first integer is greater than the first integer, print an error message. 4. Print "program complete and then stop Example input and output Ima Student Enter a number from 1 to 5: 0 Input is out of range Enter a number from 1 to 5: 3 This means that next section is done 3 times. Enter the first number: 3 Enter the second number: 3 Absolute value of the difference Sum of the values 3 0 Enter the first number: 2 Enter the second number: 8 Absolute value of the difference Sum of values 35 Enter the first number: 5 Enter the second number:-2 Absolute value of the difference = 7 Sum of values cannot be determined Program ending Specifics . Use only the instructions covered to date. No functions, etc - Document the beginning of your program with your name, class, and assignment number e Document every instruction

Explanation / Answer

ScreenShot

------------------------------------------

Program

#data section
.data
student_name: .asciiz "Ima Student "
prompt: .asciiz "Enter a number from 1 to 5: "
error_msg: .asciiz "Input is out of range "
input1: .asciiz "Enter the first number: "
input2: .asciiz "Enter the second number: "
diff: .asciiz "Absolute value of the difference= "
sum: .asciiz "sum of the values= "
greater_msg: .asciiz "Sum of the values cannot be determined "
nextLine: .asciiz " "
#Main section
.text
#Address of the student name in a0
lui $1,0x00001001
ori $4,$1,0x00000000
#system call to display name
addi $v0,$0,4
syscall
check:
#Address of the prompt in a0
lui $1,0x00001001
ori $4,$1,0x0000000e
#system call to display name
addi $v0,$0,4
syscall
#read data
addi $v0,$0,5
syscall
#if less than 1
slti $1,$2,1
bne $1,$0,error
#if greater than 5
sgt $1,$2,5
bne $1,$0,error
#otherwise
#store value for looping into s0
add $s0,$0,$v0
looping:
#beq $s0,0,exit
addi $1,$0,0x00000000
beq $1,$16,exit
#first input prompt
lui $1,0x00001001
ori $4,$1,0x00000042
addi $v0,$0,4
syscall
#read
addi $v0,$0,5
syscall
#store input in t0
add $t0,$0,$v0
#second input prompt
lui $1,0x00001001
ori $4,$1,0x0000005b
addi $v0,$0,4
syscall
#read input
addi $v0,$0,5
syscall
#store input in t0
add $t1,$0,$v0
#Check numbers
#ble $t0,$t1,summing1
slt $1,$9,$8
beq $1,$0,summing1
#Otherwise
sub $t2,$t1,$t2
#display abosolute message
lui $1,0x00001001
ori $4,$1,0x00000075
addi $v0,$0,4
syscall
#Display absolute value
sub $t2,$t0,$t1
add $a0,$0,$t2
addi $v0,$0,1
syscall
#Prine next line
lui $1,0x00001001
ori $4,$1,0x000000d4
addi $v0,$0,4
syscall
#sum display
lui $1,0x00001001
ori $4,$1,0x000000ac
addi $v0,$0,4
syscall
addi $s0,$s0,-1
j looping
summing1:
sub $t2,$t0,$t1
#t2 is negative
slti $1,$10,0x00000000
bne $1,$0,printPositive
#beq $t2,0,printSame
addi $1,$0,0x00000000
beq $1,$0,printSame
#Absolute display
lui $1,0x00001001
ori $4,$1,0x00000075
addi $v0,$0,4
syscall
#Display value
mul $t1,$t1,-1
add $t2,$t0,$t1
add $a0,$0,$t2
li $v0,1
syscall
#Prine next line
lui $1,0x00001001
ori $4,$1,0x000000d4
addi $v0,$0,4
syscall
#print sum
lui $1,0x00001001
ori $4,$1,0x000000ac
addi $v0,$0,4
syscall
#print nextline
lui $1,0x00001001
ori $4,$1,0x000000d4
addi $v0,$0,4
syscall
addi $s0,$s0,-1
j looping
printSame:
lui $1,0x00001001
ori $4,$1,0x00000075
addi $v0,$0,4
syscall
add $a0,$0,$0
addi $v0,$0,1
syscall
#print nextline
lui $1,0x00001001
ori $4,$1,0x000000d4
addi $v0,$0,4
syscall
lui $1,0x00001001
ori $4,$1,0x00000098
addi $v0,$0,4
syscall
add $a0,$0,$t1
addi $v0,$0,1
syscall
#Prine next line
lui $1,0x00001001
ori $4,$1,0x000000d4
addi $v0,$0,4
syscall
addi $s0,$s0,-1
j looping
printPositive:
lui $1,0x00001001
ori $4,$1,0x00000075
addi $v0,$0,4
syscall
addi $1,$0,0xffffffff
mul $4,$10,$1
li $v0,1
syscall
#print nextline
lui $1,0x00001001
ori $4,$1,0x000000d4
addi $v0,$0,4
syscall
li $s1,0
loop:
bgt $t0,$t1,next
add $s1,$s1,$t0
addi $t0,$t0,1
j loop
next:
lui $1,0x00001001
ori $4,$1,0x00000098
addi $v0,$0,4
syscall
add $a0,$0,$s1
addi $v0,$0,1
syscall
#print nextline
lui $1,0x00001001
ori $4,$1,0x000000d4
addi $v0,$0,4
syscall
addi $s0,$s0,-1
j looping
exit:
addi $v0,$0,10
syscall
error:
#Address of the error message
lui $1,0x00001001
ori $4,$1,0x0000002b
#system call to display name
addi $v0,$0,4
syscall
j check

----------------------------------

Output

Ima Student

Enter a number from 1 to 5: 0
Input is out of range
Enter a number from 1 to 5: 3
Enter the first number: 2
Enter the second number: 8
Absolute value of the difference= 6
sum of the values= 35
Enter the first number: 3
Enter the second number: 3
Absolute value of the difference= 0
sum of the values= 3
Enter the first number: 5
Enter the second number: -2
Absolute value of the difference= 7
Sum of the values cannot be determined

-- program is finished running --

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote