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 but please do not
# remove or change the initializations to $sp $s $s or $s
li $spxfffffc # Starting address of empty stack
li $sxf # UART base address
li $s arrayptr # Array head pointer
li $s arrayptr # 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
arrayptr: # Label pointing to word array
space
main:
jal pollUART
nop
jal periodcheck
nop
jal spacecheck
nop
jal casecheck
nop
jal arraypush
nop
j main
nop
# The "pollUART" function should poll the status register of the UART.
# If the bit position ready bit is set to then it
# should copy the receive buffer's value into $v and send
# a clear status command to the command register before
# returning a return statement is already included In order to
# receive full credit, $s must contain the base address of the UART
# and must be used with the appropriate offsets to access UART
# registers and buffers
pollUART:
lw $t$s # Load UART status register
andi $t $tx # Mask to get the ready bit
beq $t $zero, pollUART # If not ready, return
lw $v$s # Load the received character
sw $zero, $s # Clear the status register
jr $ra
nop
# The "periodcheck" function should check if the current character $v
# is a period If it is a period then the function should go to the
# label, "palindromecheck". If the character is not a period then it
# should use the included return.
periodcheck:
li $t # is the ASCII value of
beq $v $t palindromecheck
jr $ra
nop
# The "spacecheck" function should check if the current character $v
# 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.
spacecheck:
li $t # is the ASCII value of
beq $v $t main # return to main if space
jr $ra
nop
# The "casecheck" function should perform a single inequality check.
# If the current character $v is greater than the ASCII value of Z
# which indicates the current character is lowercase, then it should convert
# the value of $v to the uppercase equivalent and then return. If the
# current character $v is already uppercase meaning the inequality
# mentioned before was not true then the function should return without
# performing a conversion.
casecheck:
li $t
li $t
slt $t $v $t # checks if uppercase
beq $v $t return # jumps if uppercase
addiu $v $v # changes lowercase to uppercase
return:
jr $ra
nop
# The "arraypush" function should save the current character $v to the
# current location of the tail pointer, $s 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.
arraypush:
sw $v$s
addiu $s $s
jr $ra
nop
# The "palindromecheck" 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, $s and from the back towards the frontusing the tail
# pointer, $s 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 ie 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 "arraypush" 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.
palindromecheck:
addiu $s $s # point tail pointer to last char
loop:
lw $t$s # load char from head
lw $t$s # load char from tail
bne $t $t notpalindrome
addiu $s $s # increment head pointer
addiu $s $s # decrement tail pointer
beq $s $s loop
ispalindrome:
li $a
call projectprint # display "Yes"
j resetpointers
nop
notpalindrome:
li $a
call projectprint # display No
j resetpointers
nop
resetpointers:
li $s arrayptr # restores head pointer
li $s arrayptr # restores tail pointer
jr $ra
nop
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
