Question
I have two ASCII strings and I am trying to convert them into a bit string in MIPS QtSpim. Converting the ASCII strings into bit
I have two ASCII strings and I am trying to convert them into a bit string in MIPS QtSpim. Converting the ASCII strings into bit string are already done in one of the subprograms called Binary. However, I need help with printing the bit strings that are generated in the Binary subprogram. Here are the ASCII strings:
HELLO WORLD#!3 (str1 in the code)
CRLEO93 (str2 in the code)
.data
wrd1: .word 0
wrd2: word 0
main:
la $a0, str1 # Load and print string asking for string li $v0, 4 syscall
li $v0, 8 # take in input
la $a0, str2 jal Binary sw $v0, wrd1
la $a0, str4
jal Binary
sw $v0, wrd2
Binary:
# $a0 parameter contains string
# $v0 used for the BinarySet
# $t0 used to hold nextChar in the string
# $t3 used to hold the mask for the str[j] character
li $v0, 0 # BinarySet is set as empty set
outer: lb $t0, 0($a0)
beq $t0, 0, end_outer #end of string
inner: blt $t0, 97, end_inner # a value is 97
bgt $t0, 122, end_inner # 'z' is 122
addi $t0, $t0, -32 # capitalize ASCII character
end_inner:
inner2: blt $t0, 65, end_if_2 # 'A' is 65
bgt $t0, 90, end_if_2 # 'Z' is 90
addi $t8, $t0, -65 # determine bit position
li $t3, 1 # Build mask
sllv $t3, $t3, $t8 # Continue to build mask
or $v0, $v0, $t3 # update BinarySet by bitwise OR
end_inner2:
addi $a0, $a0, 1 # walk-pointer to str[index+1]
j outer
end_outer:
jr $ra
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started