Compare commits

..

No commits in common. "eeda21def6a53d97204a2bdb9eee137283a997e1" and "cbb315da346418384d8fbe3d29fb3d292960d8ad" have entirely different histories.

View File

@ -1,39 +1,41 @@
.data .data
sentence: // 0x8000102c
.ascii "Become a Prograammermmmmmrr\0" // x7 = PC+(imm <<()
match: // x7 =
.ascii "abc \0"
out: // =
.space 256, 0 // 0x8000 0000 +
// 0x8001 0000
// = 0x8001 0000
// aupic x7, 1
sentence: .ascii "Become a Prograammermmmmmrr\0"
// ^
// ^
.text .text
.align 2 .align 2
.globl _start .globl _start
_start: _start:
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
la a0, match # Load address of match into a0 la t2, sentence # Load the address of sentence into t2
la s0, out # Load address of out into s0 li t0, 0x72 // ascii 'm'
iteruj_match: li t1, 0x00 // licznik wystapien 'm'
lbu a1, 0(a0) # Load unsigned byte from match into a1
beq a1, zero, done_match # If end of match string (\0), exit inner loop
bne t1, a1, 1f # If t1 != a1, skip increment print_loop:
lbu s10, 0(s0) # Load current counter value from out into s10 lbu t3, 0(t2) # Load the byte (character) from address in t2
addi s10, s10, 1 # Increment counter beq t3, zero, done_print # If character is zero (null terminator), exit loop
sb s10, 0(s0) # Store updated counter back to out
bne t3, t0, 1f
addi t1, t1, 1
1: 1:
j iteruj_match # Jump back to start of inner loop addi t2, t2, 1 # Increment pointer to the next character
done_match: j print_loop # Repeat the loop
addi t0, t0, 1 # Increment pointer to the next character in sentence done_print:
j read_str # Jump back to start of outer loop ebreak # End program (or use an exit system call)
read_str_done:
ebreak # End program