String case: Difference between revisions

m
→‎{{header|68000 Assembly}}: actually writes back now, it didn't before.
m (→‎{{header|68000 Assembly}}: actually writes back now, it didn't before.)
Line 213:
;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.overhead ;if less than a, keep looping.
 
CMP.B #'z',D0 ;compare to ascii code for z
BHI Uppercase.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.
.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
 
.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.overhead ;if less than A, keep looping.
 
CMP.B #'Z',D0 ;compare to ascii code for Z
BHI LowerCase .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.
.overhead:
MOVE.B D0,(A0)+ ;store the result and get ready to read the next letter.
BRA LowerCase ;next letter
.Terminated:
Line 243 ⟶ 251:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ToggleCase:
MOVE.B (A0)+,D0 ;load a letter and inc the pointer to the next letter
BEQ .Terminated ;we've reached the null terminator.
 
Line 250 ⟶ 258:
 
CMP.B #'A',D1 ;compare to ascii code for A
BCS ToggleCaseoverhead ;if less than A, keep looping.
 
CMP.B #'Z',D1 ;compare to ascii code for Z
BHI ToggleCaseoverhead ;if greater than Z, keep looping
 
EOR.B #%00100000,D0 ;swaps the case of the letter
overhead:
 
MOVE.B D0,(A0)+ ;store the result
BRA ToggleCase ;next letter
.Terminated:
1,489

edits