Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using Mips Instructions below: .data legend: .asciiz \"0 = UpUp, 1 = UpLo, 2 = L

ID: 3590617 • Letter: U

Question

using Mips Instructions below:

.data

legend: .asciiz "0 = UpUp, 1 = UpLo, 2 = LoUp, 3 = LoLo "

# UpUp = Uppercase-Uppercase, UpLo = Uppercase-Lowercase, ...

inPrompt1: .asciiz "Enter 1st alphabet (A-Z; a-z): "

inPrompt2: .asciiz " Enter 2nd alphabet (A-Z; a-z): "

outLab1: .asciiz " and "

outLab2: .asciiz " are "

############################ code segment ################################

.text

.globl main

main:

li $v0, 4

la $a0, legend   

syscall # print legend

la $a0, inPrompt1   

syscall # print input prompt 1

li $v0, 12

syscall # read 1st alphabet

move $t1, $v0

li $v0, 4

la $a0, inPrompt2   

syscall # print input prompt 2

li $v0, 12

syscall # read 2nd alphabet

move $t2, $v0

li $v0, 11

li $a0, ' '

syscall

move $a0, $t1   

syscall # 1st alphabet

li $v0, 4

la $a0, outLab1   

syscall # print " and "

li $v0, 11

move $a0, $t2   

syscall # 2nd alphabet

li $v0, 4

la $a0, outLab2   

syscall # print " are "

li $v0, 1

li $a0, 0 # initialize desired output to 0

##########################################################

# Insert NO MORE THAN 7 lines of code that involve ONLY

# bit manipulating instructions (ANDing, ORing, XORing,

# NORing and shifting - only whatever that are needed)

# so that the program will work just like the sample runs

# shown at the bottom (some blank lines edited out).

# HINT: Risking telling the obvious, the instructions you

# insert are related to bringing the value in $a0

# from the initial value of 0 to the final desired

# value (which should be either 0, 1, 2 or 3 when

# printed as an integer).

# You MUST test your completed program for AT LEAST the

# test cases shown (and include the result in hardcopy).

##########################################################

syscall # display desired output

##########################################################

  

li $v0, 10 # exit gracefully

syscall

########################## sample test runs ##############################

# 0 = UpUp, 1 = UpLo, 2 = LoUp, 3 = LoLo

# Enter 1st alphabet (A-Z; a-z): P

# Enter 2nd alphabet (A-Z; a-z): M

# P and M are 0

# -- program is finished running --

#

# Reset: reset completed.

#

# 0 = UpUp, 1 = UpLo, 2 = LoUp, 3 = LoLo

# Enter 1st alphabet (A-Z; a-z): A

# Enter 2nd alphabet (A-Z; a-z): t

# A and t are 1

# -- program is finished running --

#

# Reset: reset completed.

#

# 0 = UpUp, 1 = UpLo, 2 = LoUp, 3 = LoLo

# Enter 1st alphabet (A-Z; a-z): b

# Enter 2nd alphabet (A-Z; a-z): E

# b and E are 2

# -- program is finished running --

#

# Reset: reset completed.

#

# 0 = UpUp, 1 = UpLo, 2 = LoUp, 3 = LoLo

# Enter 1st alphabet (A-Z; a-z): q

# Enter 2nd alphabet (A-Z; a-z): i

# q and i are 3

# -- program is finished running --

######################## end sample test runs ############################

Explanation / Answer

.data

legend: .asciiz "0 = UpUp, 1 = UpLo, 2 = LoUp, 3 = LoLo "

# UpUp = Uppercase-Uppercase, UpLo = Uppercase-Lowercase, ...

inPrompt1: .asciiz "Enter 1st alphabet (A-Z; a-z): "

inPrompt2: .asciiz " Enter 2nd alphabet (A-Z; a-z): "

outLab1: .asciiz " and "

outLab2: .asciiz " are "

############################ code segment ################################

.text

.globl main

main:

li $v0, 4

la $a0, legend   

syscall # print legend

la $a0, inPrompt1   

syscall # print input prompt 1

li $v0, 12

syscall # read 1st alphabet

move $t1, $v0

li $v0, 4

la $a0, inPrompt2   

syscall # print input prompt 2

li $v0, 12

syscall # read 2nd alphabet

move $t2, $v0

li $v0, 11

li $a0, ' '

syscall

move $a0, $t1   

syscall # 1st alphabet

li $v0, 4

la $a0, outLab1   

syscall # print " and "

li $v0, 11

move $a0, $t2   

syscall # 2nd alphabet

li $v0, 4

la $a0, outLab2   

syscall # print " are "

li $v0, 1

li $a0, 0 # initialize desired output to 0

# Upper-case and Lower case letters are stored in ASCII format.

# Upper(65-90): 01000001 - 01011010

# Lower(97-122): 01100001 - 01111010

# Upper & Lower has same msb1 & msb2 but they are differ by msb3 onwards.

# For Upper letters msb3 is 0 and 1 for Lower.

# By placing these two msb3 bits side by side we can get required values for $a0

# The first and second characters msb3 will decide contents of $a0

# If input is Upper,Upper - msb3 of upper, msb3 of upper = 00 = 0

# If input is Upper,Lower - msb3 of upper, msb3 of lower = 01 = 1

# If input is Lower,Upper - msb3 of lower, msb3 of upper = 10 = 2

# If input is Lower,Lower - msb3 of lower, msb3 of lower = 11 = 3

sra $t8, $t1, 4 # $t8 contains msb1 of 1st char to msb4 bit

sra $t9, $t2, 5 # $t9 contains msb1 of 2nd char to msb3 bit

and $t8, 2 # $t8 contains lsb2 bit as corresponding upper or lower bit, remaining are zeros

and $t9, 1 # $t9 contains lsb1 bit as corresponding upper or lower bit, remaining are zeros

or $a0, $t8, $t9 # moving $a0 to $t8 oring $t9

##########################################################

# Insert NO MORE THAN 7 lines of code that involve ONLY

# bit manipulating instructions (ANDing, ORing, XORing,

# NORing and shifting - only whatever that are needed)

# so that the program will work just like the sample runs

# shown at the bottom (some blank lines edited out).

# HINT: Risking telling the obvious, the instructions you

# insert are related to bringing the value in $a0

# from the initial value of 0 to the final desired

# value (which should be either 0, 1, 2 or 3 when

# printed as an integer).

# You MUST test your completed program for AT LEAST the

# test cases shown (and include the result in hardcopy).

##########################################################

syscall # display desired output

##########################################################

  

li $v0, 10 # exit gracefully

syscall

########################## sample test runs ##############################

# 0 = UpUp, 1 = UpLo, 2 = LoUp, 3 = LoLo

# Enter 1st alphabet (A-Z; a-z): P

# Enter 2nd alphabet (A-Z; a-z): M

# P and M are 0

# -- program is finished running --

#

# Reset: reset completed.

#

# 0 = UpUp, 1 = UpLo, 2 = LoUp, 3 = LoLo

# Enter 1st alphabet (A-Z; a-z): A

# Enter 2nd alphabet (A-Z; a-z): t

# A and t are 1

# -- program is finished running --

#

# Reset: reset completed.

#

# 0 = UpUp, 1 = UpLo, 2 = LoUp, 3 = LoLo

# Enter 1st alphabet (A-Z; a-z): b

# Enter 2nd alphabet (A-Z; a-z): E

# b and E are 2

# -- program is finished running --

#

# Reset: reset completed.

#

# 0 = UpUp, 1 = UpLo, 2 = LoUp, 3 = LoLo

# Enter 1st alphabet (A-Z; a-z): q

# Enter 2nd alphabet (A-Z; a-z): i

# q and i are 3

# -- program is finished running --

######################## end sample test runs ############################