Question

In: Computer Science

MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...

MIPS Assembly Language

Write 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 is 34000, your program should print out an error since the largest 16 bit signed integer is 215 - 1 = 32767.

Solutions

Expert Solution

.data

ask_str1: .asciiz "Enter a number between -32768 , 32767 :: "

printError: .asciiz "Number out of range!! Exiting...."

result_str: .asciiz ""

printMessage: .asciiz "Binary conversion is : "

.align 2

.text

.globl __start

__start:

# ask and store the first number

li $v0, 4

la $a0, ask_str1

syscall

li $v0, 5

syscall

bgt $v0,32767,exit

blt $v0,-32768,exit

move $s0, $v0

li $v0, 4

la $a0, printMessage

syscall

jal print_bin

# New Line

li $v0, 10

syscall

print_bin:

add $t0, $zero, $s0 # put our input ($a0) into $t0

add $t1, $zero, $zero # Zero out $t1

addi $t3, $zero, 1 # load 1 as a mask

sll $t3, $t3, 15 # move the mask to appropriate position

addi $t4, $zero, 16 # loop counter

loop:

and $t1, $t0, $t3 # and the input with the mask

beq $t1, $zero, print # Branch to print if its 0

add $t1, $zero, $zero # Zero out $t1

addi $t1, $zero, 1 # Put a 1 in $t1

j print

print: li $v0, 1

move $a0, $t1

syscall

srl $t3, $t3, 1

addi $t4, $t4, -1

bne $t4, $zero, loop

jr $ra

exit:

li $v0, 4

la $a0, printError

syscall

output:


Related Solutions

Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a mips assembly language program that asks the user to enter an alphabetic character (either...
Write a mips assembly language program that asks the user to enter an alphabetic character (either lower or upper case)and change the case of the character from lower to upper and from upper to lower and display it.
Can someone write a method in MIPS assembly language that asks the user for a hexadecimal...
Can someone write a method in MIPS assembly language that asks the user for a hexadecimal value and converts it into a decimal? I will thumbsup if its right
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a mips assembly language program. Ask the user whether he wants to repeat the program:...
Write a mips assembly language program. Ask the user whether he wants to repeat the program: "\nRepeat [y/n]? ". Use service code 12 to read a character and the branch instruction to repeat the main function if the user input is character 'y'.
Write a MIPS Assembly language program to request a file name from the user, open the...
Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write out the contents to the console. This is what I have so far: .data    fileName:   .space 100    prompt1:   .asciiz "Enter the file name: "    prompt2:    .asciiz ""    prompt3:   .asciiz "\n"    buffer:    .space 4096 .text    main:        #        li $v0, 4        la $a0, prompt1       ...
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....
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.
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.
This is to be done using MIPS assembly language. Display the following menus, ask user to...
This is to be done using MIPS assembly language. Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program. 1. Menu item 1 2. Menu item 2 3. Menu item 3 0. Quit Please select from above menu (1-3) to execute one function. Select 0 to quit
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT