Question: Problem 1 (40 points) Write a MIPS program (which must be named as hw4_prob1.s ) that will read in a base (as an integer) and
Problem 1 (40 points) Write a MIPS program (which must be named as hw4_prob1.s) that will read in a base (as an integer) and a value (nonnegative integer but as an ASCII string) in that base and print out the decimal value; you must implement a function (which accepts a base and an address for a string as parameters, and returns the value) and call the function from the main program. The base will be given in decimal and will be between 2 and 36, and the digits for the values will be in set [0...9, a...z]. You can assume that no overflow will occur and the value is valid in the given base.
I would appreciate some comments for me to understand the code.
Also I have done the following code which takes the base and the number, but I still need to do the function for the convertion.
.data str: .asciiz "Enter a base (between 2 and 36 in decimal): " str1: .asciiz "Enter a number in base " str2: .asciiz "The value in decimal is:" str3: .asciiz ":" str4: .asciiz "Error, wrong value" .text Main: li $v0, 4 # $system call code for print_str la $a0, str # $address of string to print syscall # print the string
li $v0, 5 # $system call code for read_int syscall # read the int move $s0, $v0 #store value li $t1, 37 slt $t0, $s0, $t1 beq $t0,1, IF lit $v0, 4 la $a0, str4 syscall j Main
IF: li $t2, 1 slt $t3, $t2, $s0 beq $t0,1, STR lit $v0, 4 la $a0, str4 syscall j Main STR: li $v0,4 la $a0,str1 syscall move $a0,$s0 li $v0, 1 syscall li $v0, 4 la $a0, str3 syscall li $v0, 5 syscall move $s1, $a0 j CONV CONV:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
