zlicz/counter.S

46 lines
1.1 KiB
ArmAsm
Raw Permalink Normal View History

2025-03-11 11:24:13 +00:00
.data
sentence:
.ascii "Become a Prograammermmmmmrr\0"
match:
2025-03-18 11:18:50 +00:00
.ascii "Babc m\0"
2025-03-11 11:24:13 +00:00
out:
.space 256, 0
2025-03-11 11:20:07 +00:00
.text
.align 2
2025-03-18 11:10:32 +00:00
.globl _start
2025-03-18 11:03:54 +00:00
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-18 11:18:50 +00:00
2025-03-18 11:03:54 +00:00
lbu a1, 0(a0)
beq a1, zero, done_match
2025-03-11 11:20:07 +00:00
2025-03-18 11:03:54 +00:00
bne t1, a1, 1f
2025-03-13 11:25:33 +00:00
2025-03-18 11:18:50 +00:00
lbu s10, 0(s2)
2025-03-18 11:03:54 +00:00
addi s10, s10, 1
sb s10, 0(s2)
2025-03-13 11:25:33 +00:00
2025-03-11 11:20:07 +00:00
1:
2025-03-18 11:18:50 +00:00
addi a0, a0, 1
addi s2, s2, 1
2025-03-18 11:03:54 +00:00
j iteruj_match
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