Repeat a string: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) (added langur language example) |
PatGarrett (talk | contribs) (→{{header|360 Assembly}}: Section added) |
||
Line 7: | Line 7: | ||
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). |
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). |
||
<br><br> |
<br><br> |
||
=={{header|360 Assembly}}== |
|||
<lang 360asm>* Repeat a string - 19/04/2020 |
|||
REPEATS CSECT |
|||
USING REPEATS,R13 base register |
|||
B 72(R15) skip savearea |
|||
DC 17F'0' savearea |
|||
SAVE (14,12) save previous context |
|||
ST R13,4(R15) link backward |
|||
ST R15,8(R13) link forward |
|||
LR R13,R15 set addressability |
|||
XPRNT C24,24 print c24 |
|||
LA R1,PARMLST pg=repeat(cx,ii) - repeat('abc ',6) |
|||
BAL R14,REPEAT call repeat |
|||
XPRNT PG,L'PG print pg |
|||
L R13,4(0,R13) restore previous savearea pointer |
|||
RETURN (14,12),RC=0 restore registers from calling save |
|||
REPEAT CNOP 0,4 procedure repeat(b,a,i) |
|||
STM R2,R8,REPEATSA save registers |
|||
L R2,0(R1) @b=%r1 |
|||
L R3,4(R1) @a=%(r1+4) |
|||
L R4,8(R1) @i=%(r1+8) |
|||
LR R5,R3 length(a) before a |
|||
SH R5,=H'2' @lengh(a) |
|||
LH R6,0(R5) l=length(a) |
|||
LR R7,R6 l |
|||
BCTR R7,0 l-1 |
|||
L R8,0(R4) i=%r4 |
|||
LTR R8,R8 if i<=0 |
|||
BNP RET then return |
|||
LOOP EX R7,MVCX move a to b len R6 |
|||
AR R2,R6 @b+=l |
|||
BCT R8,LOOP loop i times |
|||
LM R2,R8,REPEATSA restore registers |
|||
RET BR R14 return |
|||
PARMLST DC A(PG,CX,II) parmlist |
|||
REPEATSA DS 7F local savearea |
|||
MVCX MVC 0(0,R2),0(R3) move @ R3 to @ R2 |
|||
C24 DC 6C'xyz ' constant repeat - repeat('xyz ',6) |
|||
LCX DC AL2(L'CX) lengh(cc) |
|||
CX DC CL4'abc ' cx |
|||
II DC F'6' ii |
|||
PG DC CL80' ' pg |
|||
REGEQU |
|||
END REPEATS </lang> |
|||
{{out}} |
|||
<pre> |
|||
xyz xyz xyz xyz xyz xyz |
|||
abc abc abc abc abc abc |
|||
</pre> |
|||
=={{header|4DOS Batch}}== |
=={{header|4DOS Batch}}== |