From d42add2c88d35ce5e5cda67173c049aebb6f9177 Mon Sep 17 00:00:00 2001 From: mpabi Date: Tue, 11 Mar 2025 11:20:41 +0000 Subject: [PATCH] ai refactored --- counter.S | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/counter.S b/counter.S index 7442d28..a661dbc 100644 --- a/counter.S +++ b/counter.S @@ -1,50 +1,31 @@ -.data - sentence: - .ascii "Become a Prograammermmmmmrr\0" - // ^ - - match: - .ascii "abc \0" - // ^ - - out: - .space 256, 0 - .text .align 2 .globl _start _start: - - la t0, sentence # Load the address of sentence into t2 - + la t0, sentence # Load the address of sentence into t0 read_str: + lbu t1, 0(t0) # Load unsigned byte from sentence into t1 + beq t1, zero, read_str_done # If end of string (\0), exit loop - - lbu t1, 0(t0) - beq t1, zero, read_str_done - - la a0, match - la s0, out + la a0, match # Load address of match into a0 + la s0, out # Load address of out into s0 iteruj_match: + lbu a1, 0(match) # Load unsigned byte from match into a1 + beq a1, zero, done_match # If end of match string (\0), exit inner loop - lbu a1, 0(match) - beq a1, zero, done_match - - bne t1, a1, 1f - lbu s10, 0(out) - addi s10, s10, 1 - sb s10, 0(out) + bne t1, a1, 1f # If t1 != a1, skip increment + lbu s10, 0(out) # Load current counter value from out into s10 + addi s10, s10, 1 # Increment counter + sb s10, 0(out) # Store updated counter back to out 1: - j iteruj_match + j iteruj_match # Jump back to start of inner loop done_match: - addi t0, t0, 1 # Increment pointer to the next character - j read_str + addi t0, t0, 1 # Increment pointer to the next character in sentence + j read_str # Jump back to start of outer loop read_str_done: - - ebreak # End program (or use an exit system call) - + ebreak # End program