Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
95
Task/String-case/MIPS-Assembly/string-case.mips
Normal file
95
Task/String-case/MIPS-Assembly/string-case.mips
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
ToUpper:
|
||||
;input: $a0 = pointer to beginning of string
|
||||
;clobbers: $t0,$t1,$t2
|
||||
|
||||
li $t1,'a'
|
||||
li $t2,'z'
|
||||
ToUpper_again:
|
||||
|
||||
lbu $t0,($a0)
|
||||
nop
|
||||
|
||||
beqz $t0,ToUpper_done ;if char is null terminator, exit
|
||||
nop
|
||||
|
||||
bltu $t0,$t1,ToUpper_overhead ;if char stored in $t0 < 'a', skip
|
||||
nop
|
||||
|
||||
bgtu $t0,$t2,ToUpper_overhead ;if char stored in $t0 > 'z', skip
|
||||
nop
|
||||
|
||||
|
||||
andi $t0,$t0,0xDF ;otherwise, do the work.
|
||||
sb $t0,($a0)
|
||||
|
||||
ToUpper_overhead:
|
||||
addiu $a0,1
|
||||
b ToUpper_again
|
||||
nop
|
||||
|
||||
ToUpper_done:
|
||||
jr ra
|
||||
nop
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
ToLower:
|
||||
;input: $a0 = pointer to beginning of string
|
||||
;clobbers: $t0,$t1,$t2
|
||||
|
||||
li $t1,'A'
|
||||
li $t2,'Z'
|
||||
ToLower_again:
|
||||
|
||||
lbu $t0,($a0)
|
||||
nop
|
||||
|
||||
beqz $t0,ToUpper_done ;not a typo, I did this to save space.
|
||||
nop
|
||||
|
||||
bltu $t0,$t1,ToLower_overhead ;if char stored in $t0 < 'a', skip
|
||||
nop
|
||||
|
||||
bgtu $t0,$t2,ToLower_overhead ;if char stored in $t0 > 'z', skip
|
||||
nop
|
||||
|
||||
|
||||
ori $t0,$t0,0x20
|
||||
sb $t0,($a0)
|
||||
|
||||
ToLower_overhead:
|
||||
addiu $a0,1
|
||||
b ToLower_again
|
||||
nop
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
ToggleCase:
|
||||
li $t1,'A'
|
||||
li $t2,'Z'
|
||||
|
||||
lbu $t0,($a0)
|
||||
nop
|
||||
|
||||
beqz $t0,ToggleCase_done
|
||||
nop
|
||||
|
||||
bltu $t0,$t1,ToggleCase_next
|
||||
nop
|
||||
bleu $t0,$t2,ToggleCase_Xor
|
||||
nop
|
||||
ToggleCase_next:
|
||||
addiu $t1,0x20 ;li $t1,'a'
|
||||
addiu $t2,0x20 ;li $t2,'z'
|
||||
|
||||
bltu $t0,$t1,ToggleCase_overhead
|
||||
nop
|
||||
bgtu $t0,$t2,ToggleCase_overhead
|
||||
nop
|
||||
ToggleCase_Xor:
|
||||
xori $t0,$t0,0x20
|
||||
sb $t0,($a0)
|
||||
ToggleCase_overhead:
|
||||
addiu $a0,1
|
||||
b ToggleCase
|
||||
nop
|
||||
ToggleCase_done:
|
||||
jr ra
|
||||
nop
|
||||
Loading…
Add table
Add a link
Reference in a new issue