Repeat a string: Difference between revisions
Content added Content deleted
(Added Easylang) |
Not a robot (talk | contribs) (Add 8080 Assembly) |
||
Line 156: | Line 156: | ||
even</syntaxhighlight> |
even</syntaxhighlight> |
||
=={{header|8080 Assembly}}== |
|||
<syntaxhighlight lang="asm8080"> org 100h |
|||
jmp demo |
|||
; Repeat the string at DE into HL, B times |
|||
repeat: mvi c,'$' ; string terminator |
|||
xra a ; repeat 0x? |
|||
ora b |
|||
mov m,c ; then empty string |
|||
rz |
|||
rpt1: push d ; save begin of string to repeat |
|||
chcpy: ldax d ; copy character from input to output |
|||
mov m,a |
|||
inx d ; advance pointers |
|||
inx h |
|||
cmp c ; end of string? |
|||
jnz chcpy |
|||
pop d ; restore begin of string to repeat |
|||
dcx h ; move back past terminator in copy |
|||
dcr b ; done yet? |
|||
jnz rpt1 ; if not add another copy |
|||
ret |
|||
demo: lxi d,ha ; get string to repeat |
|||
lxi h,buf ; place to store result |
|||
mvi b,5 ; repeat 5 times |
|||
call repeat |
|||
lxi d,buf ; print result using CP/M call |
|||
mvi c,9 |
|||
jmp 5 |
|||
ha: db 'ha$' ; string to repeat |
|||
buf: ds 32 ; place to store repeated string</syntaxhighlight> |
|||
{{out}} |
|||
<pre>hahahahaha</pre> |
|||
=={{header|8th}}== |
=={{header|8th}}== |
||
<syntaxhighlight lang="forth">"ha" 5 s:* |
<syntaxhighlight lang="forth">"ha" 5 s:* |