-
Notifications
You must be signed in to change notification settings - Fork 0
/
strlen.asm
43 lines (40 loc) · 1.09 KB
/
strlen.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
.text
main:
addiu $sp,$sp,-4
sw $ra,0($sp)
lui $a0,0x1001
jal strlen
nop
lw $ra,0($sp)
addiu $sp,$sp,4
jr $ra
nop
# $t0と$t1に$a0の作業用コピー
strlen:
addiu $sp,$sp,-4
add $t0, $a0,$zero
add $t1, $a0,$zero # 処理中に$a1が変わった場合の対策
L1:
lbu $t2,0($t0) # xVal = *x
beq $t2,$zero,L2 # if(xVal == 0) goto L2
addi $t0,$t0,1 # x++ (先頭アドレスのインクリメント)
j L1
L2:
# 元のアドレスと移動したアドレスとの差を取る
sub $t2,$t0, $t1
add $v0,$zero,$t2 # return $a0 - $t0
lw $s0,0($sp)
addi $sp,$sp,4
jr $ra
nop
.data
word:
.byte 0x41 # A
.byte 0x42 # B
.byte 0x43 # C
.byte 0x44 # D
.byte 0x45 # E
.byte 0x46 # F
.byte 0x47 # G
.byte 0x48 # H
.byte 0x00 # Null文字