Menu

[solved]-Anyone Help Write Required Code Mips Please Encodertypes Program Variables Fields R Type I Q38987112

Can anyone help to write the required code forMIPS please

# encodertype.s: This program has variables for the
# fields of an R-type instruction (op, rs, rt, rd, shamt,funct)
# that the user sets for whatever R-type instrucion they wantto
# encode. The main program them calls the functionencodertype:
#
# unsigned encodertype(unsigned opc, unsigned rs, unsignedrt,
# unsigned rd, unsigned shamt, unsigned funct);
#
# which encodes the R-type instruction, returning theinstruction.
#
# The main program then decodes the instruction and outputs thevalue of
# each field for checking.
#
# The function interface and main program are written for you! Allyou have
# to do is to fill in the missing code in the function to actuallydo
# the encoding, following the instructions. SEE THE END OF THISFILE.
#
# This program should be run with the exception handler.
#
   .data
# Alter these values for the instruction you want to encode.
# The default encoded one is for: srl $a0, $t9, 21
opc: .word 0
rs: .word 0
rt: .word 29
rd: .word 4
shamt: .word 21
funct: .word 2
opcstring: .asciiz “nThe encoded opc is:”
rsstring: .asciiz “nThe encoded rs is:”
rtstring: .asciiz “nThe encoded rt is:”
rdstring: .asciiz “nThe encoded rd is:”
shamtstring: .asciiz “nThe encoded shamt is:”
functstring: .asciiz “nThe encoded funct is:”

.text
.globl main
main:
addiu $sp,$sp,-28
sw $ra,24($sp)
# prepare for the call to encodertype
lw $a0,opc
lw $a1,rs
lw $a2,rt
lw $a3,rd
lw $t0,shamt
sw $t0,16($sp)
lw $t0,funct
sw $t0,20($sp)
jal encodertype
# result in $v0
# move the result to $t9 since we need $v0 for syscalls
move $t9,$v0
# print opc result
la $a0,opcstring
li $v0,4
syscall
srl $a0,$t9,26
li $v0,1
syscall
# print rs result
la $a0,rsstring
li $v0,4
syscall
srl $a0,$t9,21
andi $a0,$a0,0x1f
li $v0,1
syscall
# print rt result
la $a0,rtstring
li $v0,4
syscall
srl $a0,$t9,16
andi $a0,$a0,0x1f
li $v0,1
syscall
# print rd result
la $a0,rdstring
li $v0,4
syscall
srl $a0,$t9,11
andi $a0,$a0,0x1f
li $v0,1
syscall

# print shamt result
la $a0,shamtstring
li $v0,4
syscall
srl $a0,$t9,6
andi $a0,$a0,0x1f
li $v0,1
syscall
# print funct result
la $a0,functstring
li $v0,4
syscall
andi $a0,$t9,0x3f
li $v0,1
syscall

# return from main
lw $ra,24($sp)
addiu $sp,$sp,28
jr $ra

.globl encodertype
encodertype:
lw $t0,16($sp) #shamt
lw $t1,20($sp) #funct
#####################
# INSERT YOUR CODE IN THE SPACE BELOW.
#
# You can assume that the following values are ALREADY
# in the following registers:
# – opc is in $a0
# – rs is in $a1
# – rt is in $a2
# – rd is in $a3
# – shamt is in $t0
# – funct is in $t1
#
# You should use your knowledge of logical operatorinstructions
# and shift instructions to line up the six values with the
# appropriate bit widths. Your final encoded instruction MUST
# go in $v0.
#
# You can use any t-registers you like, and you can modify thea-regs
# if you like. DO NOT USE OTHER REGISTERS!
#####################

   # Your code here…

# Ensure the result is in $v0!

# This returns to main.
jr $ra

Expert Answer


Answer to Can anyone help to write the required code for MIPS please # encodertype.s: This program has variables for the # fields … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *