zlicz/counter.S

43 lines
1.3 KiB
ArmAsm
Raw Normal View History

2025-03-11 11:24:13 +00:00
.data
sentence:
.ascii "Become a Prograammermmmmmrr\0"
match:
.ascii "abc \0"
out:
.space 256, 0
2025-03-11 11:20:07 +00:00
.text
.align 2
.globl _start
2025-02-20 10:57:53 +00:00
_start:
2025-03-11 11:20:41 +00:00
la t0, sentence # Load the address of sentence into t0
2025-03-13 11:25:33 +00:00
2025-03-11 11:20:07 +00:00
read_str:
2025-03-11 11:20:41 +00:00
lbu t1, 0(t0) # Load unsigned byte from sentence into t1
beq t1, zero, read_str_done # If end of string (\0), exit loop
2025-03-11 11:20:07 +00:00
2025-03-11 11:20:41 +00:00
la a0, match # Load address of match into a0
2025-03-13 11:25:33 +00:00
la s2, out # Load address of out into s0
2025-03-11 11:20:07 +00:00
iteruj_match:
2025-03-11 11:24:13 +00:00
lbu a1, 0(a0) # Load unsigned byte from match into a1
2025-03-11 11:20:41 +00:00
beq a1, zero, done_match # If end of match string (\0), exit inner loop
2025-03-11 11:20:07 +00:00
2025-03-11 11:20:41 +00:00
bne t1, a1, 1f # If t1 != a1, skip increment
2025-03-13 11:25:33 +00:00
lbu s10, 0(s2) # Load current counter value from out into s10
2025-03-11 11:20:41 +00:00
addi s10, s10, 1 # Increment counter
2025-03-13 11:25:33 +00:00
sb s10, 0(s2) # Store updated counter back to out
2025-03-11 11:20:07 +00:00
1:
2025-03-13 11:29:17 +00:00
addi s0, s0, 1
2025-03-11 11:20:41 +00:00
j iteruj_match # Jump back to start of inner loop
2025-03-11 11:20:07 +00:00
done_match:
2025-02-20 10:57:53 +00:00
2025-03-11 11:20:41 +00:00
addi t0, t0, 1 # Increment pointer to the next character in sentence
j read_str # Jump back to start of outer loop
2025-02-20 10:57:53 +00:00
2025-03-11 11:20:07 +00:00
read_str_done:
2025-03-11 11:20:41 +00:00
ebreak # End program