String case: Difference between revisions

m
Line 1,949:
 
=={{header|MIPS Assembly}}==
ThisThese exampleexamples modifiesmodify a string in place. <code>$a0</code> is assumed to contain a pointer to the string ''in RAM,;'' writes to ROM will obviously not have the desired effect.
===Convert to upper case===
 
<lang mips>ToUpper:
;input: $a0 = pointer to beginning of string
Line 1,962:
nop
 
beq $t0,ToUpper_done ;if char is null terminator, exit
nop
 
Line 1,982:
ToUpper_done:
jr ra
nop</lang>
===Convert to lower case===
 
<lang mips>ToLower:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ToUpper:
;input: $a0 = pointer to beginning of string
;clobbers: $t0,$t1,$t2
Line 1,996 ⟶ 1,995:
nop
 
beq $t0,ToUpper_doneToLower_done ;not a typo, I did this to save space.
nop
 
Line 2,012 ⟶ 2,011:
addiu $a0,1
b ToLower_again
nop
 
ToLower_done:
jr ra
nop</lang>
 
1,489

edits