Question: Why isn't is reading the UART? # you may add initializations after line 1 0 , but please do not # remove or change the

Why isn't is reading the UART?
# you may add initializations after line 10, but please do not
# remove or change the initializations to $sp, $s0, $s1, or $s2
li $sp,0x10fffffc # Starting address of empty stack
li $s0,0xf0000000 # UART base address
li $s1, array_ptr # Array head pointer
li $s2, array_ptr # Array tail pointer
#
# Do not make changes to the jump to main, the allocation of
# memory for the array, or the main loop
#
j main
nop
array_ptr: # Label pointing to 100 word array
.space 100
main:
jal poll_UART
nop
jal period_check
nop
jal space_check
nop
jal case_check
nop
jal array_push
nop
j main
nop
# The "poll_UART" function should poll the status register of the UART.
# If the 2^1 bit position (ready bit) is set to 1 then it
# should copy the receive buffer's value into $v0 and send
# a clear status command (2^1) to the command register before
# returning (a return statement is already included). In order to
# receive full credit, $s0 must contain the base address of the UART
# and must be used with the appropriate offsets to access UART
# registers and buffers
poll_UART:
lw $t0,0($s0) # Load UART status register
andi $t0, $t0,0x01 # Mask to get the ready bit
beq $t0, $zero, poll_UART # If not ready, return
lw $v0,4($s0) # Load the received character
sw $zero, 0($s0) # Clear the status register
jr $ra
nop
# The "period_check" function should check if the current character ($v0)
# is a period ("."). If it is a period then the function should go to the
# label, "palindrome_check". If the character is not a period then it
# should use the included return.
period_check:
li $t0,46 # 46 is the ASCII value of '.'
beq $v0, $t0, palindrome_check
jr $ra
nop
# The "space_check" function should check if the current character ($v0)
# is a space (""). If it is then it should jump to "main" so
# that it skips saving the space character. If not it should
# use the included return.
space_check:
li $t0,32 # 32 is the ASCII value of ''
beq $v0, $t0, main # return to main if space
jr $ra
nop
# The "case_check" function should perform a single inequality check.
# If the current character ($v0) is greater than the ASCII value of 'Z',
# which indicates the current character is lowercase, then it should convert
# the value of $v0 to the uppercase equivalent and then return. If the
# current character ($v0) is already uppercase (meaning the inequality
# mentioned before was not true) then the function should return without
# performing a conversion.
case_check:
li $t1,90
li $t2,1
slt $t3, $v0, $t1 # checks if uppercase
beq $v0, $t2, return # jumps if uppercase
addiu $v0, $v0,-32 # changes lowercase to uppercase
return:
jr $ra
nop
# The "array_push" function should save the current character ($v0) to the
# current location of the tail pointer, $s2. Then it should increment the
# tail pointer so that it points to the next element of the array. Last
# it should use the included return statement.
array_push:
sw $v0,0($s2)
addiu $s2, $s2,4
jr $ra
nop
# The "palindrome_check" subroutine should be jumped to by the period
# check function if a period is encountered. This subroutine should contain
# a loop that traverses the array from the front towards the back (using the
# head pointer, $s1) and from the back towards the front(using the tail
# pointer, $s2). If the string is a palindrome then as the array is traversed
# the characters pointed to should be equal. If the characters are not equal
# then the string is not a palindrome and the print function should be used
# to print "No". If the pointers cross (i.e. the head pointer's address is
# greater than or equal to the tail pointer's address) and the compared
# characters are equal then the string is a palindrome and "Yes" should be
# printed.
#
# Remember to restore the head and tail pointers to the first element
# of the array before the subroutine jumps back to main to begin processing the
# next string. Also, keep in mind that because the tail pointer is updated at
# the end of "array_push" it technically points one element past the last
# character in the array. You will need to compensate for this by either
# decrementing the pointer once at the start of the array or using an offset
# from this pointer's address.
palindrome_check:
addiu $s2, $s2,-4 # point tail pointer to last char
loop:
lw $t0,0($s1) # load char from head
lw $t1,0($s2) # load char from tail
bne $t0, $t1, not_palindrome
addiu $s1, $s1,4 # increment head pointer
addiu $s2, $s2,-4 # decrement tail pointer
beq $s1, $s2, loop
is_palindrome:
li $a0,1
call project3_print # display "Yes"
j reset_pointers
nop
not_palindrome:
li $a0,0
call project3_print # display "No"
j reset_pointers
nop
reset_pointers:
li $s1, array_ptr # restores head pointer
li $s2, array_ptr # restores tail pointer
jr $ra
nop

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!