# Partial code to implement a bit-string of letters .data str1: .asciiz "Cape3?!AE" str2: .asciiz "A d y B**#&." set1: .word 0 set2: .word 0 unionSet: .word 0 .text .globl main main: la $a0, str1 jal bitString sw $v0, set1 la $a0, str2 jal bitString sw $v0, set2 # pass sets in $a0 and $a1; returns union in $v0 lw $a0, set1 lw $a1, set2 jal union sw $v0, unionSet li $v0, 10 syscall union: # pass in bitString sets in $a0 and $a1; returns union bitString in $v0 or $v0, $a0, $a1 jr $ra bitString: # bitString Algorithm: # resultSet = {} # index = 0 # while True: # nextChar = str[index] # if nextChar == 0 then // the NULL character # break # end if # if nextChar >= ascii of 'a' and nextChar <= ascii of 'z' then # convert it upper-case letter by subtracting 32 # end if # if nextChar >= ascii of 'A' and nextChar <= ascii of 'Z' then # resultSet = resultSet U {nextChar} # end if (no else because we are ignoring non-letters) # index = index + 1 # end while # return resultSet # Register Usage - NOTE: doesn't call anything so by using only $a and $t registers, doesn't need to save on stack # $a0 parameter contains address of .asciiz string, but will be walked down the string # $v0 used for the resultSet # $t0 used to hold nextChar ASCII value # $t3 used to hold the mask for the str[index] character li $v0, 0 # resultSet = {} while: lb $t0, 0($a0) beq $t0, 0, end_while # NULL character (0) detected at end of .asciiz if_1: blt $t0, 97, end_if_1 # ASCII for 'a' is 97 bgt $t0, 122, end_if_1 # ASCII for 'z' is 122 addi $t0, $t0, -32 # convert to upper-case letter end_if_1: if_2: blt $t0, 65, end_if_2 # ASCII for 'A' is 65 bgt $t0, 90, end_if_2 # ASCII for 'Z' is 90 addi $t8, $t0, -65 # determine bit position of letter in bit-string li $t3, 1 # Build mask: start with 1 at right-most position sllv $t3, $t3, $t8 # Build mask: move 1 to correct position to finish building mask or $v0, $v0, $t3 # update resultSet in $v0 = $v0 bit-wise-OR with mask end_if_2: addi $a0, $a0, 1 # walk-pointer to str[index] to next character j while end_while: jr $ra