Assignment Write a MIPS assembly program using MARS which allows the user to con
ID: 652092 • Letter: A
Question
Assignment
Write a MIPS assembly program using MARS which allows the user to convert numbers between bases.
Inputs from the user
1
Explanation / Answer
# MIPS Programming Assignment 3 .data msg: .asciiz " Please enter an integer: " #input prompt error: .asciiz " Your number is out of range, try again!" array: .space 20 #reserve space for 5-integer array .text main: la $t3, array #load pointer for traversing array la $s0, array #load initial position of array #initialize counter for loop add $t0, $t0, $zero #set counter to 0 li $t1, 5 #set maximum number of passes to 5 #initialize counter for hexadecimal loop add $t4, $t4, $zero #set counter to 0 la $t5, array #load pointer for traversing array #loop to insert numbers into array insert_loop: beq $t0, $t1, hexadecimal_loop #if $t0 = $t1 then exit loop li $v0, 4 #system call code for printing string la $a0, msg syscall li $v0, 5 #system call for reading integer syscall move $t2, $v0 #move read integer to $t2 bltz $t2, error_msg #bltz = branch if ($t2) 32768 sw $t2, ($t3) #stores t2 in t3 array addi $t3, $t3, 4 #increment array by 4 (move to next index) addi $t0, $t0, 1 #increment counter by 1 j insert_loop #loop for hexadecimal subprogram hexadecimal_loop: add $s2, $s2, $zero #set counter for loop li $s3, 5 #set max number of passes to 5 beq $t4, $t1, exit #when $t4 = $t1, then exit loop lw $s1, ($t5) #store array value into $s1 add $a0, $zero, $s1 #"move" value to $a0 to use as parameter jal hexadecimal addi $t5, $t5, 4 #increment array by 4 (move to next index) #hexadecimal subprogram hexadecimal: add $t5, $a0, $zero #copy parameter to $t5 beq $s2, $s3, return_result #when $s2 = $s3 then exit loop andi $t6, $t5, 15 #logical AND on $t5 and 15 addi $t7, $t7, 10 #variable to check again bgt $t6, $t7, more_than_ten #if $t6 > 10 blt $t6, $t7, less_than_ten #if $t6 < 10 addi $s2, $s2, 1 #increment counter by 1 #error message display error_msg: li $v0, 4 la $a0, error syscall j insert_loop less_than_ten: addi $t7, $t6, 10 srl $t5, $t5, 4 j hexadecimal more_than_ten: addi $t7, $t6, -10 addi $t7, $t7, 65 srl $t5, $t5, 4 j hexadecimal exit: li $v0, 10 # System call code for exiting program syscallRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.