Strip comments from a string: Difference between revisions

(Added Arturo implementation)
Line 47:
apples ; pears # and bananas
</pre>
 
=={{header|68000 Assembly}}==
<lang 68000devpac>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</lang>
 
=={{header|Action!}}==
1,489

edits