Question

In: Computer Science

All in MIPS assembly 1. Have the user input a 32 bit binary string 2. convert...

All in MIPS assembly

1. Have the user input a 32 bit binary string

2. convert that into decimal

3. Print the decimal

Solutions

Expert Solution

.data

msg1: .asciiz

msg2: .asciiz

buffer: .space

.text

main:

li $v0, 4

la $a0 ,msg1

syscall

li $v0, 8

la $a0 ,buffer

li $a1, 33

move $t2 , $a0

syscall

li $s1, 32

li $s2, 30

biToDecLoop:

li $t0 , '0'

li $t1, '1'

lb $t3, ($t2)

beq $t3, $t0, binaryZero

beq $t3, $t1, binaryOne

binaryZero:

subi $s2. $s2, 1

j biToDecNext

binaryOne

add $t3,$t3,1

mul $t3,$t3,2

subi $s2,$s2,1

bne $s2, $zero, binaryOne

move $t4, $t3

add $t5, $t5,$t4

li $t0,32

li $t1,33

beq $s1, $t0, addTwo

beq $s1, $t1, addOne

j biToDecNext

addTwo:                                         # Check if there is a 1 in the second to last index of string
        add $t5, $t5, 2                         # Add 2 to total ($t5)
        j biToDecNext

addOne:                                         # Check if there is a 1 in the last index of string
        add $t5, $t5, 1                         # Add 1 to total ($t5)
        j biToDecNext   
        
biToDecNext:
        add $t2, $t2, 1                         
        subi $s1, $s1, 1                        # Decrement outer loop counter
        bne $s1, $zero, biToDecLoop             # Loop until outer counter reaches zero

end: 
        li      $v0, 4                                                                          
        la      $a0, newLine                                    
        syscall 

        li      $v0, 4                                                                  
        la      $a0, msg2                                       
        syscall 
        
        #move $a0, $t5                          
        li      $v0, 1                          
        la      $a0 ($t5)
        syscall

        li $v0, 10  
        syscall
        

:


Related Solutions

MIPS ASSEMBLY Have the user input a string and then be able to make changes to...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S....
Design a transducer to convert a binary string into octal. For example the bit string 001101110...
Design a transducer to convert a binary string into octal. For example the bit string 001101110 should produce 156. Please complete the code to account for the 7 cases of 3 digit binary strings. //Function binaryToOctal takes a char array digits of length 3 //Pre: digits contains 3 binary digits. //Post: function returns the octal number equivalent to the 3 binary digits int binaryToOctal( char digits[], int 3){ int number; if(digits[0]=='0') if (digits[1]=='1') if (digits[2]=='0') return 2;//found "010" else return...
Write a MIPS assembly program that prompts the user first for a string, then for a...
Write a MIPS assembly program that prompts the user first for a string, then for a character. The program should then search the string for the character and print out the number of times the character appears in the string. You can use as many restrictions as you want, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
Write a simple MIPS program that asks the user to input a string and then a...
Write a simple MIPS program that asks the user to input a string and then a character. The program should then count how many times that character appears in the string and print out that value. Please use comments.
IN MIPS ASSEMBLY LANGUAGE Write an assembly program to read three 32-bit signed integers from the...
IN MIPS ASSEMBLY LANGUAGE Write an assembly program to read three 32-bit signed integers from the user. Determine the smallest of these three numbers and display this result. Don’t use loops. Prompt the user for each entered integer. Your output should look something like the following example. Enter an integer: 7556 Enter an integer: -22984 Enter an integer: 8875 -22984
Write a program in MIPS assembly language to convert an ASCII number string containing positive and...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and negative integer decimal strings, to an integer. Your program should expect register $a0 to hold the address of a nullterminated string containing some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $v0. If a non-digit character appears anywhere in the string, your program should stop with...
Write a program that read the input from user and convert it to binary and hex...
Write a program that read the input from user and convert it to binary and hex in C language.
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Q1.Convert C46C000016 into a 32-bit single-precision IEEE floating-point binary number.
Q1.Convert C46C000016 into a 32-bit single-precision IEEE floating-point binary number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT