Question: Can some one help me with this code? It's a UART Palindrome checker using PLP Tool Here's the code I came up with so far:
Can some one help me with this code? It's a UART Palindrome checker using PLP Tool
Here's the code I came up with so far:
.org 0x10000000 li $sp, 0x10fffffc #initializes stack li $s0, 0xf0000000 #initializes UART Command Register li $s1, 0xf0000004 # Initializes UART Status Register li $s2, 0xf0000008 # Initializes UART Recieve Buffer array_ptr: # Label pointing to 100 word array .space 100 start: li $a0, array_ptr # arrays assigned to register $a0 move $a1, $a0 # register a1 equals address of array at postion [0] UART_status_read: lw $t0, 0($s1) # UART status li $t1, 0b10 # Mask 2nd Bit and $t2, $t0, $t1 #Mast rdy bit beq $t2,$zero, UART_status_read #if status is zero, repeat UART_status_read nop lw $v0, 0($s2) #else get buffer to register $v0 sw $t1, 0($s0) #send clear to command register space_checker: li $s3, 0x20 beq $v0, $s3, UART_status_read nop uppercase_checker: li $t5, 0x41 li $t6, 0x5A slt $t7, $t6, $v0 slt $t8, $v0, $t5 beq $t7, $t8, check_for_zero nop check_for_zero: beq $t7, $zero, change_lowercase nop j period_checker nop change_lowercase: addiu $v0, $v0, 32 j store_array nop period_checker: li $t9, 0x2E beq $v0, $t9, main nop store_array: sw $v0, 0($a1) addiu $a1, $a1, 4 j UART_status_read nop main: move $a2, $a0 li $t5, 0 push_loop: lw $t7, 0($a2) push $t7 addiu $t5, $t5, 1 addiu $a2, $a2, 4 slt $s6, $a2, $a1 bne $s6, $zero, push_loop nop pop_loop: pop $t7 lw $t8, 0($a0) bne $t7, $t8, assign_0 addiu $a0, $a0, 4 addiu $t5, $t5, -1 bne $t5, $zero, pop_loop nop j assign_1 nop assign_0: li $a0, 0 call project3_print nop j start nop assign_1: li $a0, 1 call project3_print nop j start nop
li $a0, control_message_p3 jal libplp_uart_write_string_p3 nop control_flow_trap_p3: j control_flow_trap_p3 nop
string_yes_p3: .asciiz "Yes "
string_no_p3: .asciiz " No "
control_message_p3: .asciiz "Error: Program entered project3_print.asm due to missing control flow at the end of main.asm "
project3_print: push $ra bne $a0 $0, set_ptr_yes nop li $a0, string_no_p3 j print_string_p3 nop set_ptr_yes: li $a0, string_yes_p3
print_string_p3: jal libplp_uart_write_string_p3 nop pop $ra return
This is the project3_print.asm code that the previous code is referring to: # From PLP UART Library
libplp_uart_write_p3: lui $t0, 0xf000 #uart base address libplp_uart_write_loop_p3: lw $t1, 4($t0) #get the uart status andi $t1, $t1, 0x01 #mask for the cts bit beq $t1, $zero, libplp_uart_write_loop_p3 nop sw $a0, 12($t0) #write the data to the output buffer sw $t1, 0($t0) #send the data! jr $31 nop
libplp_uart_write_string_p3: #we have a pointer to the string in a0, just loop and increment until we see a \0 move $t9, $31 #save the return address move $t8, $a0 #save the argument libplp_uart_write_string_multi_word_p3: lw $a0, 0($t8) #first 1-4 characters ori $t0, $zero, 0x00ff #reverse the word to make it big endian and $t1, $t0, $a0 #least significant byte sll $t1, $t1, 24 srl $a0, $a0, 8 and $t2, $t0, $a0 #second byte sll $t2, $t2, 16 srl $a0, $a0, 8 and $t3, $t0, $a0 #third byte sll $t3, $t3, 8 srl $a0, $a0, 8 #last byte in a0 or $a0, $t1, $a0 or $a0, $t2, $a0 or $a0, $t3, $a0 beq $a0, $zero, libplp_uart_write_string_done_p3 nop ori $t7, $zero, 4 libplp_uart_write_string_loop_p3: jal libplp_uart_write_p3 #write this byte addiu $t7, $t7, -1 srl $a0, $a0, 8 bne $a0, $zero, libplp_uart_write_string_loop_p3 nop beq $t7, $zero, libplp_uart_write_string_multi_word_p3 addiu $t8, $t8, 4 #increment for the next word libplp_uart_write_string_done_p3: jr $t9 #go home nop
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
