String case: Difference between revisions

m (→‎{{header|68000 Assembly}}: actually writes back now, it didn't before.)
Line 1,947:
Lower Case of alphaBETA is alphabeta
</pre>
 
=={{header|MIPS Assembly}}==
This example modifies a string in place.
<lang mips>ToUpper:
;input: $a0 = pointer to beginning of string
;clobbers: $t0,$t1,$t2
 
li $t1,'a'
li $t2,'z'
ToUpper_again:
 
lb $t0,($a0)
nop
 
beq $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
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ToUpper:
;input: $a0 = pointer to beginning of string
;clobbers: $t0,$t1,$t2
 
li $t1,'A'
li $t2,'Z'
ToLower_again:
 
lb $t0,($a0)
nop
 
beq $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</lang>
 
=={{header|mIRC Scripting Language}}==
1,489

edits