Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- display: .asciiz "Please, input the Alphanumeric string:\n"
- sparse: .asciiz "Sparse"
- intermediate: .asciiz "Intermediate"
- plentiful: .asciiz "Plentiful"
- space: .asciiz "\n"
- str: .space 200 # initialize array with 200 characters space available
- temp: .space 7
- period: .asciiz "."
- .text
- .globl main
- main:
- li $t2, 0 # word_end = 0
- li $t3, 0 # word_hex = 0
- li $t6, 0 # last_word = 0
- li $t1, 0 # word_str = 0
- li $t4, 200 # constant used for max
- li $t0, 0
- li $s4, 0x20 # period
- li $s5, 0x2E # space
- la $s3, temp
- la $a0, display # load address of string to print
- li $v0, 4 # instruction to output
- syscall # make the syscall
- la $a0, str
- li $a1, 200
- syscall
- for: bgt $t0, 200, flag # for loop, will branch if 200 characters are reached print period
- li $v0, 8 # read character, getchar=c
- syscall # make the syscall
- bne $v0, $s4, str1 # branch if not equal to period
- li $t6, 1 # if equal to space, flag for end
- move $v0, $s5 # make equal to space so it can still calculate lasr word
- j else_if # jump to else if to make last calculation
- str1: la $a0, str # set register $a0 to str, 200 spaces available for input
- li $a1, 200 # Load into register $a1 200, max permitted
- sb $v0, ($s3) # store the charater
- add $s3, $s3, $t0 # array offset
- addi $t2, $t2, 1 # increment word_end by 1
- bgt $v0, 70, else_if # branch if greater than 'F'
- blt $v0, 48, else_if # branch if less than '0'
- bgt $v0, 65, word_hex # branch if greater than 'A'
- blt $v0, 57, word_hex # branch if less than '9'
- word_hex:
- addi $t4, $t4, 1 # add to counter of HEX characters
- else_if: bne $v0, $s5, else2 # branch if character is not equal to space
- subi $t1, $t1, 1 # word_str-1
- sub $t5, $t2, $t1 # word_end - word_str-1
- bne $t1, $t3 else1 # branch if not equal to word_hex
- subi $t5, $t0, 1 # k-1
- sll $t5, $t0, 2 # shift of k-1
- add $t5 $t5, $s3 # add t5 to base address str
- lw $t7, 0($t5) # t7 contains str[k-1]
- beq $t7, $s5, else1 # branch if equal to space
- strlen1: # now check third condition, strlen1
- lbu $t0, 0($s2) # load the next character into t0
- beqz $t0, out # check for the null character
- addi $s2, $s2, 1 # increment the string pointer
- addi $s6, $s6, 1 # increment the count
- j strlen # return to the top of the loop
- #out:
- #bne
- #beq temp, 1, else1 # branch if strlen = 1
- li $t5, 0 # counter = 0
- li $t7, 0 # sum = 0
- for1: # running through the valid hex values to check if # or letter
- subi $t2, $t2, 2 # word end - 2
- move $t3, $t2 # word end = i
- blt $t3, $t1, tempc # branch if i is less than word str
- sll $s6, $t3, 2 # convert the word to byte
- add $s6, $s6, $s2 # add to base address of str
- lw $s7, 0($s6) # s7 contains str[i]
- bgt $s7, 57, letter # branch if greater than '9'
- subi $s7, $s7, 48 # if not, subtract 55 because it's a #
- j sum # no need to check if letter, go to temp array
- letter:
- subi $s7, $s7, 55
- sum:
- sll $t5, $t5, 4 # multiply counter by 4
- sllv $t5, $s0, $t5 # num*2^(4*counter)
- add $t7, $t5, $t7 # add result + sum, store it in sum
- addi $t5, $t5, 1 # counter +1, 16 will be raised to this value
- addi $t3, $t3, 1 # decrease i by 1
- blt $t7, $t4, for1 # branch back if sum<max
- move $t4, $t7 # if not change new max to sum
- j for1 # go back to check next valid hex
- tempc:
- #sprintf
- la $a0, temp # load addres of str
- li $v0, 4 # print call
- syscall # make the syscall
- move $a0, $t7 # load sum to print
- li $v0, 1 # print call
- syscall # make the syscall
- li $s5, 0 # j = 0
- move $t3, $t1 # i = word str
- strlen:
- lbu $t1, 0($a0) # load the next character into t1
- beqz $t1, plus # check for the null character
- addi $a0, $a0, 1 # increment the string pointer
- addi $t0, $t0, 1 # increment the count
- j strlen # return to the top of the loop
- # word str + strlen of temp arr CHECKKKK
- plus:
- for2: bgt $t3, $t5, out # branch out if i > wordstr + strlen(temparr)
- addi $s5, $s5, 1 # j++
- sll $t3, $s5, 2 # change word to byte temp array
- add $t3, $t3, $s1 # add to base address
- lw $t0, 0($t3) # load
- sll $t2, $t3, 2 # change word to byte str[i]
- add $t2, $t2, $s2 # add to base add str
- lw $t5, 0($t2) # load
- move $t0, $t5 # move temp array[j++] into str[i]
- j for2 # go back to for loop till conditions not met
- out:
- #K=WORD_STR+STRLEN(TEMP_ARRAY);
- sll $s5, $t0, 2
- add $s5, $s5, $s2
- lw $s0, 0($s5)
- move $s0, $s4 # STR[K]=' '
- li $t3, 0 # word hex = 0
- move $t2, $t0 # word end = k
- addi $t1, $t2, 1 # word str = word end ++
- else1:
- li $t3, 0
- move $t1, $t2
- else2:
- li $t3, 0
- flag:
- #bne $t6, 1, for
- sll $t3, $s5, 2
- add $t3, $t3, $s1
- lw $t0, 0($t3)
- li $t0, 46
- move $a0, $t0 # print period
- li $v0, 1 # print call
- syscall # make the syscall
- print: la $a0, str # load addres of str, will print non hex non period character
- li $v0, 4 # print call
- syscall # make the syscall
- #find if sparse, intermediate or pletiful
- exit:
- li $v0, 10 # instruction for exit program
- syscall # make the syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement