Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Mulawski, Evan
- # Program 2
- # Weighted String Output
- # 2011-10-11
- .data
- inBuf:
- .space 80
- st_prompt:
- .asciiz "Enter a new input line: "
- newLine:
- .asciiz "\n"
- Tabchar:
- .word ' ', 5
- .word '#', 6
- .word '(', 4
- .word ')', 4
- .word '*', 3
- .word '+', 3
- .word ',', 4
- .word '-', 3
- .word '.', 4
- .word '/', 3
- .word '0', 1
- .word '1', 1
- .word '2', 1
- .word '3', 1
- .word '4', 1
- .word '5', 1
- .word '6', 1
- .word '7', 1
- .word '8', 1
- .word '9', 1
- .word ':', 4
- .word 'A', 2
- .word 'B', 2
- .word 'C', 2
- .word 'D', 2
- .word 'E', 2
- .word 'F', 2
- .word 'G', 2
- .word 'H', 2
- .word 'I', 2
- .word 'J', 2
- .word 'K', 2
- .word 'L', 2
- .word 'M', 2
- .word 'N', 2
- .word 'O', 2
- .word 'P', 2
- .word 'Q', 2
- .word 'R', 2
- .word 'S', 2
- .word 'T', 2
- .word 'U', 2
- .word 'V', 2
- .word 'W', 2
- .word 'X', 2
- .word 'Y', 2
- .word 'Z', 2
- .word 'a', 2
- .word 'b', 2
- .word 'c', 2
- .word 'd', 2
- .word 'e', 2
- .word 'f', 2
- .word 'g', 2
- .word 'h', 2
- .word 'i', 2
- .word 'j', 2
- .word 'k', 2
- .word 'l', 2
- .word 'm', 2
- .word 'n', 2
- .word 'o', 2
- .word 'p', 2
- .word 'q', 2
- .word 'r', 2
- .word 's', 2
- .word 't', 2
- .word 'u', 2
- .word 'v', 2
- .word 'w', 2
- .word 'x', 2
- .word 'y', 2
- .word 'z', 2
- weights:
- .space 80
- .text
- .globl main
- main:
- la $a0, newLine
- li $v0, 4
- syscall
- jal getline
- # > print what was entered
- li $v0, 4
- la $a0, inBuf
- syscall
- # <
- li $t1, 80 # total characters
- li $t0, 0 # inBuf array index
- next_char:
- lb $a3, inBuf($t0) # save inBuf element into $a3
- beq $a3, 10, exit
- jal lin_srch # call linear search
- addi $t0, $t0, 1 # increment inBuf index
- b next_char
- # non-terminating exit to print the weighted output
- exit:
- la $a0, weights
- la $t8, ($a0)
- li $v0, 4
- syscall
- b main # return to main to present the input prompt again
- getline:
- la $a0, st_prompt # prompt to enter a new line
- li $v0, 4
- syscall
- la $a0, inBuf # read a new line
- li $a1, 80
- li $v0, 8
- syscall
- jr $ra
- lin_srch:
- li $s6, 0 # tabchar index
- rept:
- lb $t4, Tabchar($s6) # loads what's in Tabchar[s6] into $t4
- beq $a3, $t4, done # if character == tabchar[i], goto done
- addi $s6, $s6, 8 # incremement i 8 bytes
- blt $s6, 608, rept # if counter < end of tabchar goto rept
- done:
- lw $t4, Tabchar+4($s6) # load value of the weight
- addi $t4, $t4, 48 # modifying it to be an ascii value
- sb $t4, weights($t0) # puts weight into weights[t0]
- jr $ra
- #termination
- fin:
- move $a0, $t1
- li $v0, 1
- syscall
- li $v0, 10
Add Comment
Please, Sign In to add comment