Question

In: Computer Science

Write a MIPS assembly language program that inputs a floating-point number and shows its internal 32-bit...

Write a MIPS assembly language program that inputs a floating-point number and shows its internal 32-bit representation as a 8-digit hexadecimal representation. For example: 2.5 decimal is 10.1 binary, which normalized is 1.01x21 and would be stored in the IEEE format as 0100 0000 0010 0000 0000 0000 0000 0000 which is 0x40200000

Solutions

Expert Solution

.data
msg: .asciiz "\nPlease enter an unsigned integer: " #input prompt
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) < zero
bgt $t2, 32768, error_msg #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
syscall


Related Solutions

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 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 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 MIPS assembly language program to read an arbitrary number of integer pairs from a...
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a file. Each pair will then be multiplied together with the results being accumulated (added together) forming a sum-of-products operation. Submit your report and code here.
using Windows 32 bit framework , Write an assembly language program to find the second minimum...
using Windows 32 bit framework , Write an assembly language program to find the second minimum element (formally, second minimum is larger than the minimum but smaller than all the other elements in the array) of an array of size 100. Note: You can define the array as nbrArray DWORD 23 45 21 67 78 95 dup(?) and show that your program works for the first five elements. Display the second minimum in a message box using Input output macro
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE THE EQUATION Z=A+B-(C/D)+E please write the answer separately part A its own code and part B its own code this is microprocessor the ASSEMBLY LANGUAGE emu8086 should be written like this EX: mov ax,100h mov bx,200h etc
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...
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
Write a program that converts a given floating point binary number with a 24-bit normalized mantissa...
Write a program that converts a given floating point binary number with a 24-bit normalized mantissa and an 8-bit exponent to its decimal (i.e. base 10) equivalent. For the mantissa, use the representation that has a hidden bit, and for the exponent use a bias of 127 instead of a sign bit. Of course, you need to take care of negative numbers in the mantissa also. Use your program to answer the following questions: (a) Mantissa: 11110010 11000101 01101010, exponent:...
The number –11.375 (decimal) represented as a 32-bit floating-point binary number according to the IEEE 754...
The number –11.375 (decimal) represented as a 32-bit floating-point binary number according to the IEEE 754 standard is
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT