flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Quines : Programs that copy themselves |
| Author |
|
|
bitRAKE 22 Jan 2026, 07:25
In fasmg not only does an empty file copy itself, but "file __FILE__" also copies itself. Moving beyond these trivial examples (305 bytes):
Code: virtual A::db 'virtual|A::db ~|end virtual|repeat sizeof A|load a:1 from A:%-1|if a=7Eh|load a:%% from A:0|db 27h,a,27h|else if a=7Ch|db 10|else|db a|end if|end repeat' end virtual repeat sizeof A load a:1 from A:%-1 if a=7Eh load a:%% from A:0 db 27h,a,27h else if a=7Ch db 10 else db a end if end repeat (Of course, a smaller version is possible - down to 291.) _________________ ¯\(°_o)/¯ AI may [not] have aided with the above reply. Last edited by bitRAKE on 01 Apr 2026, 02:09; edited 1 time in total |
|||
|
|
bitRAKE 22 Jan 2026, 12:11
That's bonkers - yet, insightful.
Three distinctly different corner cases. |
|||
|
|
bitRAKE 21 Mar 2026, 02:12
A slight re-arrangement allows removing special handling for the empty line.
Code: a macro a calminstruction ?!n& take m,m jno y emit 1,10 y: arrange m,n stringify m emit lengthof m,m jno x assemble n x: end calminstruction a end macro _________________ ¯\(°_o)/¯ AI may [not] have aided with the above reply. |
|||
|
|
Tomasz Grysztar 21 Mar 2026, 09:34
I was hoping you would improve it!
|
|||
|
|
bitRAKE 21 Mar 2026, 21:33
Fold conditions together, reduce first line test/track (138 bytes):
Code: a macro a calminstruction ?!n& take,b jno z emit 1,10 assemble n z: stringify n emit lengthof n,n take b,n end calminstruction a end macro It seems something like, Code: a macro a macro ?!b& match,c b end match c equ c equ db`b,10 end macro a end macro |
|||
|
|
bitRAKE 01 Apr 2026, 01:09
It just occurred to me there is no in-place replace -- that would be a very fasm/fasmg style solution.
Another potential would be larger integer manipulation. _________________ ¯\(°_o)/¯ AI may [not] have aided with the above reply. |
|||
|
|
bitRAKE 03 Apr 2026, 15:53
Code: DB 'i\jkXikflk![Y79[Y7>9CXCJPCHGC>cfX[7XQ;7]ifd7G>CHGC>\mXc7jki`e^7XD?DH@YjnXg7;F;]]AIJ>' LOAD A:$ FROM 0 EVAL STRING A-(-1)BSWAP $/$FF*23 _________________ ¯\(°_o)/¯ AI may [not] have aided with the above reply. Last edited by bitRAKE on 03 Apr 2026, 16:32; edited 1 time in total |
|||
|
|
Tomasz Grysztar 03 Apr 2026, 16:30
Nice!
I was thinking about using EVAL to distil the classic quine idea: Code: A='db "A=",39,A,39,10,"EVAL A"' EVAL A |
|||
|
|
bitRAKE 03 Apr 2026, 17:04
You're right - I still had my head in the load/store in-place replace version.
Should just do: Code: A="[Y7>XT9>CXCJKCHGC>\mXc7jki`e^7XD?DH@YjnXg7LIF;]]AIJ>" EVAL STRING A-(-1)BSWAP 52/$FF*23 |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.