String case: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) m (→{{header|68000 Assembly}}: actually writes back now, it didn't before.) |
||
Line 213: | Line 213: | ||
;alters the string in-place. |
;alters the string in-place. |
||
MOVE.B (A0) |
MOVE.B (A0),D0 ;load a letter |
||
BEQ .Terminated ;we've reached the null terminator. |
BEQ .Terminated ;we've reached the null terminator. |
||
CMP.B #'a',D0 ;compare to ascii code for a |
CMP.B #'a',D0 ;compare to ascii code for a |
||
BCS |
BCS .overhead ;if less than a, keep looping. |
||
CMP.B #'z',D0 ;compare to ascii code for z |
CMP.B #'z',D0 ;compare to ascii code for z |
||
BHI |
BHI .overhead ;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. |
AND.B #%1101111,D0 ;this "magic constant" turns lower case to upper case, since they're always 32 apart. |
||
.overhead: |
|||
MOVE.B D0,(A0)+ ;store the letter back and increment the pointer. |
|||
;If this isn't an alphabetical character, D0 won't change and this store won't affect the string at all. |
|||
;If it was a letter, it will have been changed to upper case before storing back. |
|||
BRA UpperCase ;next letter |
BRA UpperCase ;next letter |
||
.Terminated: |
.Terminated: |
||
RTS |
RTS |
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
LowerCase: |
LowerCase: |
||
MOVE.B (A0) |
MOVE.B (A0),D0 ;load a letter |
||
BEQ .Terminated ;we've reached the null terminator. |
BEQ .Terminated ;we've reached the null terminator. |
||
CMP.B #'A',D0 ;compare to ascii code for A |
CMP.B #'A',D0 ;compare to ascii code for A |
||
BCS |
BCS .overhead ;if less than A, keep looping. |
||
CMP.B #'Z',D0 ;compare to ascii code for Z |
CMP.B #'Z',D0 ;compare to ascii code for Z |
||
BHI |
BHI .overhead ;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. |
OR.B #%00100000,D0 ;this "magic constant" turns upper case to lower case, since they're always 32 apart. |
||
.overhead: |
|||
MOVE.B D0,(A0)+ ;store the result and get ready to read the next letter. |
|||
BRA LowerCase ;next letter |
BRA LowerCase ;next letter |
||
.Terminated: |
.Terminated: |
||
Line 243: | Line 251: | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
ToggleCase: |
ToggleCase: |
||
MOVE.B (A0) |
MOVE.B (A0),D0 ;load a letter and inc the pointer to the next letter |
||
BEQ .Terminated ;we've reached the null terminator. |
BEQ .Terminated ;we've reached the null terminator. |
||
Line 250: | Line 258: | ||
CMP.B #'A',D1 ;compare to ascii code for A |
CMP.B #'A',D1 ;compare to ascii code for A |
||
BCS |
BCS overhead ;if less than A, keep looping. |
||
CMP.B #'Z',D1 ;compare to ascii code for Z |
CMP.B #'Z',D1 ;compare to ascii code for Z |
||
BHI |
BHI overhead ;if greater than Z, keep looping |
||
EOR.B #%00100000,D0 ;swaps the case of the letter |
EOR.B #%00100000,D0 ;swaps the case of the letter |
||
overhead: |
|||
MOVE.B D0,(A0)+ ;store the result |
|||
BRA ToggleCase ;next letter |
BRA ToggleCase ;next letter |
||
.Terminated: |
.Terminated: |