RosettaCodeData/Task/Strip-comments-from-a-string/68000-Assembly/strip-comments-from-a-string.68000
2023-07-01 13:44:08 -04:00

61 lines
1.1 KiB
Text

StripComments:
;prints a string but stops at the comment character
;INPUT: D7 = comment character(s) of choice
;A0 = source address of string
;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.
.loop:
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
dontCheckNext:
jsr PrintChar
bra .loop
.done:
rts
TestString:
dc.b "apples ; pears # and bananas",0