Write a program in Mars MIPS Assembly Language that asks the user for an 8-digit hexadecimal and then prints out its 32-bit binary representation, the operation of the function, the format (I, R, or J), the fields associated with the format (op, rs, rt, imm, shamt, funct), and the instruction associated with the hexadecimal. All five parts must be written as functions.
Greetings!!
Code with comments:
.data
mydata: .word 0
prompt: .asciiz "Please enter an eight digit number\n"
out: .asciiz "Equivalent binary number is:"
.text
la $a0,prompt #load
address of prompt message
li $v0,4 #parameter for
displaying string
syscall
#system call to display message
la $a0,mydata
#load address of the data variable
li $v0,5 #parameter for
reading a word
syscall
#system call for reading from the keyboard
move $t0,$v0 #copy the
number read from the keyboard into the register t0
la $a0,out
#load the address of out message
li $v0,4 #parameter for
string display
syscall
#system call for display
addi $t1, $zero, 31
# number for right shift
addi $t2, $zero, 0 # loop
count set to 0
addi $t3, $zero, 32 #
condition for exit
repeat:
beq $t2, $t3,end #if count is
32,then end
sllv $a0, $t0, $t2 #shift the
number left by one bit
srlv $a0, $a0, $t1 #shift
right 31 bits, the left shifted number so that the MSB is
available
li $v0, 1
#parameter for displaying the bit
syscall
#system call for display
addi $t2, $t2, 1 #increment
loop count
j repeat #repeat the
loop
end:
li $v0,10
#parameter for termination
syscall
#system call for termination
Output screenshot:
Hope this helps
With function:
Get Answers For Free
Most questions answered within 1 hours.