String case: Difference between revisions

Line 206:
ALPHA, BETA, GAMMA, {[(<123@_>)]}.
alpha, beta, gamma, {[(<123@_>)]}.</pre>
 
=={{header|68000 Assembly}}==
These algorithms work for any ASCII string. The implementation of actually printing the characters is left out, as it is not actually relevant to this task.
<lang 68000devpac>UpperCase:
;input: A0 = pointer to the string's base address.
;alters the string in-place.
 
MOVE.B (A0)+,D0 ;load a letter and inc the pointer to the next letter
BEQ .Terminated ;we've reached the null terminator.
 
CMP.B #'a',D0 ;compare to ascii code for a
BCS UpperCase ;if less than a, keep looping.
 
CMP.B #'z',D0 ;compare to ascii code for z
BHI Uppercase ;if greater than z, keep looping
 
AND.B #%1101111,D0 ;this "magic constant" turns lower case to upper case, since they're always 32 apart.
BRA UpperCase ;next letter
.Terminated:
RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LowerCase:
MOVE.B (A0)+,D0 ;load a letter and inc the pointer to the next letter
BEQ .Terminated ;we've reached the null terminator.
 
CMP.B #'A',D0 ;compare to ascii code for A
BCS LowerCase ;if less than A, keep looping.
 
CMP.B #'Z',D0 ;compare to ascii code for Z
BHI LowerCase ;if greater than Z, keep looping
 
OR.B #%00100000,D0 ;this "magic constant" turns upper case to lower case, since they're always 32 apart.
BRA LowerCase ;next letter
.Terminated:
RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ToggleCase:
MOVE.B (A0)+,D0 ;load a letter and inc the pointer to the next letter
BEQ .Terminated ;we've reached the null terminator.
 
MOVE.B D0,D1 ;copy the letter
AND.B #%11011111 ;convert the copy to upper case so we can check it.
 
CMP.B #'A',D1 ;compare to ascii code for A
BCS ToggleCase ;if less than A, keep looping.
 
CMP.B #'Z',D1 ;compare to ascii code for Z
BHI ToggleCase ;if greater than Z, keep looping
 
EOR.B #%00100000,D0 ;swaps the case of the letter
 
BRA ToggleCase ;next letter
.Terminated:
RTS</lang>
 
=={{header|8080 Assembly}}==
1,489

edits