RosettaCodeData/Task/Strip-comments-from-a-string/68000-Assembly/strip-comments-from-a-string.68000

62 lines
1.2 KiB
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
StripComments:
2026-04-30 12:34:36 -04:00
;prints a string but stops at the comment character
;INPUT: D7 = comment character(s) of choice
2023-07-01 11:58:00 -04:00
;A0 = source address of string
2026-04-30 12:34:36 -04:00
;up to four can be used, each takes up a different 8 bits of the register
;to omit an argument, leave its bits as zero.
2023-07-01 11:58:00 -04:00
.loop:
2026-04-30 12:34:36 -04:00
MOVE.B (A0)+,D0
CMP.B #0,D0 ;check for null terminator
beq .done
CMP.B D7,D0 ;check the first comment char
beq .done
ROR.L #8,D7
CMP.B D7,D0 ;check the second comment char
beq .done
ROR.L #8,D7
CMP.B D7,D0 ;check the third comment char
beq .done
ROR.L #8,D7
CMP.B D7,D0 ;check the fourth comment char
beq .done
ROR.L #8,D7
CMP.B #' ',D0
BNE dontCheckNext
MOVE.B (A0),D1 ;look ahead one character, if that character is a comment char or null terminator, stop here
CMP.B #0,D1
beq .done
CMP.B D7,D1
beq .done
ROR.L #8,D7
CMP.B D7,D1
beq .done
ROR.L #8,D7
CMP.B D7,D1
beq .done
ROR.L #8,D7
CMP.B D7,D1
beq .done
ROR.L #8,D7
2023-07-01 11:58:00 -04:00
dontCheckNext:
2026-04-30 12:34:36 -04:00
jsr PrintChar
bra .loop
2023-07-01 11:58:00 -04:00
.done:
2026-04-30 12:34:36 -04:00
rts
2023-07-01 11:58:00 -04:00
TestString:
2026-04-30 12:34:36 -04:00
dc.b "apples ; pears # and bananas",0