Question: This question uses the MARS MIPS simulator. The goal is to write a loop in assembly that converts hexadecimal numbers into UTF-8 binary sequences. The

This question uses the MARS MIPS simulator. The goal is to write a loop in assembly that converts hexadecimal numbers into UTF-8 binary sequences. The details are as follows:

The parts that need to be changed in main are between the comment lines Your part starts here and Your part ends here. You should also add more lines to the register assignment table, to describe what you did.

The following comments describe how the bits of j are to be rearranged to form the bits of n.This question uses the MARS MIPS simulator. The goal is to write

Here is the output from a correct solution, using MARS:a loop in assembly that converts hexadecimal numbers into UTF-8 binary sequences.

BELOW IS THE BASE CODE REFERENCED AT THE BEGINNING (lab2.txt). Code to FIX:

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# switch to the Data segment .data # global data is defined here

# Don't forget the backslash-n (newline character) Homework: .asciiz "CMPEN 331 Homework 2 " Name_1: .asciiz "First Person's name " # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# switch to the Text segment .text # the program is defined here

.globl main main: # Whose program is this? la $a0, Homework jal Print_string la $a0, Name_1 jal Print_string

# int i, j = 2, n = 3;

# for (i = 0; i

# register assignments # $s0 i # $s1 j = testcase[i] # $s2 n # $t0 address of testcase[i] # $a0 argument to Print_integer, Print_string, etc. # add to this list if you use any other registers

# initialization li $s1, 2 # j = 2 li $s2, 3 # n = 3

# for (i = 0; i # Your part starts here # Your part ends here

# print i, j and n move $a0, $s0 # i jal Print_integer la $a0, sp # space jal Print_string move $a0, $s1 # j jal Print_hex la $a0, sp # space jal Print_string move $a0, $s2 # n jal Print_hex la $a0, sp # space jal Print_string move $a0, $s1 # j jal Print_bin la $a0, sp # space jal Print_string move $a0, $s2 # n jal Print_bin la $a0, nl # newline jal Print_string

# for (i = 0; i

la $a0, done # mark the end of the program jal Print_string

jal Exit0 # end the program, default return status

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

.data # global data is defined here sp: .asciiz " " # space nl: .asciiz " " # newline done: .asciiz "All done! "

testcase: # UTF-8 representation is one byte .word 0x0000 # nul # Basic Latin, 0000 - 007F .word 0x0024 # $ (dollar sign) .word 0x007E # ~ (tilde) .word 0x007F # del

# UTF-8 representation is two bytes .word 0x0080 # pad # Latin-1 Supplement, 0080 - 00FF .word 0x00A2 # cent sign .word 0x0627 # Arabic letter alef .word 0x07FF # unassigned

# UTF-8 representation is three bytes .word 0x0800 .word 0x20AC # Euro sign .word 0x2233 # anticlockwise contour integral sign .word 0xFFFF

# UTF-8 representation is four bytes .word 0x10000 .word 0x10348 # Hwair, see http://en.wikipedia.org/wiki/Hwair .word 0x22E13 # randomly-chosen character .word 0x10FFFF

.word 0x89ABCDEF # randomly chosen bogus value

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Wrapper functions around some of the system calls # See P&H COD, Fig. A.9.1, for the complete list.

.text

.globl Print_integer Print_integer: # print the integer in register $a0 (decimal) li $v0, 1 syscall jr $ra

.globl Print_string Print_string: # print the string whose starting address is in register $a0 li $v0, 4 syscall jr $ra

.globl Exit Exit: # end the program, no explicit return status li $v0, 10 syscall jr $ra # this instruction is never executed

.globl Exit0 Exit0: # end the program, default return status li $a0, 0 # return status 0 li $v0, 17 syscall jr $ra # this instruction is never executed

.globl Exit2 Exit2: # end the program, with return status from register $a0 li $v0, 17 syscall jr $ra # this instruction is never executed

# The following syscalls work on MARS, but not on QtSPIM

.globl Print_hex Print_hex: # print the integer in register $a0 (hexadecimal) li $v0, 34 syscall jr $ra

.globl Print_bin Print_bin: # print the integer in register $a0 (binary) li $v0, 35 syscall jr $ra

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

What I have so far between my part starts here and ends here:

# Your part starts here

blt $s1, 0x80, L1

blt $s1, 0x800, L2

blt $s1, 0x10000, L3

L1: add $s2, $s1, $zero #CASE1: Sets $s2 (n) = $s1 (j)

L2: bgt $s1, 0x7ff, L3

andi $t1, $s1, 63 #Copy right 6 bits from sl to a temporary

addi $t1, $t1, 128 #Add formatting bits "10" for first byte

andi $t2, $s1, 1984 #Copy left 5 bits from sl to a temporary

sll $t2, $t2, 2 #Shift left 5 buts into position

addi $t2, $t2, 49125 #Adds formatting bits "110" for second byte

add $s2, $t3, $t1 #Add 110, a, 10, and b. Store in $s2

L3: add $s2, $s1, $zero

# Your part ends here

if (j

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!