String case: Difference between revisions

Content added Content deleted
Line 1,949: Line 1,949:


=={{header|MIPS Assembly}}==
=={{header|MIPS Assembly}}==
This example modifies 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.
These examples modify 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:
<lang mips>ToUpper:
;input: $a0 = pointer to beginning of string
;input: $a0 = pointer to beginning of string
Line 1,962: Line 1,962:
nop
nop


beq $t0,ToUpper_done ;if char is null terminator, exit
beq $t0,ToUpper_done ;if char is null terminator, exit
nop
nop


Line 1,982: Line 1,982:
ToUpper_done:
ToUpper_done:
jr ra
jr ra
nop
nop</lang>
===Convert to lower case===

<lang mips>ToLower:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ToUpper:
;input: $a0 = pointer to beginning of string
;input: $a0 = pointer to beginning of string
;clobbers: $t0,$t1,$t2
;clobbers: $t0,$t1,$t2
Line 1,996: Line 1,995:
nop
nop


beq $t0,ToUpper_done ;not a typo, I did this to save space.
beq $t0,ToLower_done
nop
nop


Line 2,012: Line 2,011:
addiu $a0,1
addiu $a0,1
b ToLower_again
b ToLower_again
nop

ToLower_done:
jr ra
nop</lang>
nop</lang>