Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
37
Task/String-matching/MIPS-Assembly/string-matching-1.mips
Normal file
37
Task/String-matching/MIPS-Assembly/string-matching-1.mips
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
InString:
|
||||
;input: $a0 = ptr to string 1
|
||||
; $a1 = ptr to string 2
|
||||
; assumes len($a1) <= len($a0)
|
||||
;out: $v0 = zero-based index where the second string is placed in the first.
|
||||
|
||||
;clobbers: $t0,$t1
|
||||
subiu sp,sp,4 ;set up a stack frame of 4 bytes.
|
||||
sw $a1,(sp)
|
||||
li $v0,0
|
||||
InString_again:
|
||||
lbu $t0,($a0)
|
||||
nop
|
||||
beqz $t0,InString_terminated
|
||||
nop
|
||||
|
||||
lbu $t1,($a1)
|
||||
nop
|
||||
beqz $t1,InString_terminated
|
||||
nop
|
||||
|
||||
bne $t0,$t1,InString_noMatch
|
||||
nop
|
||||
b InString_overhead
|
||||
addiu $a1,1
|
||||
|
||||
InString_noMatch:
|
||||
lw $a1,(sp) ;reset the substring pointer if the letters don't match
|
||||
addiu $v0,1 ;load delay slot
|
||||
InString_overhead:
|
||||
addiu $a0,1
|
||||
b InString_Again
|
||||
nop
|
||||
InString_terminated:
|
||||
addiu sp,sp,4
|
||||
jr ra
|
||||
nop
|
||||
Loading…
Add table
Add a link
Reference in a new issue