flat assembler
Message board for the users of flat assembler.
Index
> DOS > Output own source code |
Author |
|
El Tangas 30 Dec 2006, 17:30
This is a program I made some years ago, found it in a dusty folder in my HDD .
It outputs its own source (a classic programming challenge).
|
|||||||||||
30 Dec 2006, 17:30 |
|
El Tangas 30 Dec 2006, 19:17
Yeap, that's very nice and much cleaner. I knew something like that would come along, but that was pretty fast...
|
|||
30 Dec 2006, 19:17 |
|
f0dder 01 Jan 2007, 23:51
LocoDelAssembly: that's cheating, though - outputting your own source is only really interesting if done without external file access
|
|||
01 Jan 2007, 23:51 |
|
LocoDelAssembly 02 Jan 2007, 00:00
Well is not too much external, the file that has the code I posted is named "auto.asm" so the source is accessing it self. Now I'm developing a way to exclude some parts, as example:
Code: org $100 ;HIDING_ON ; Print source code mov ah, $40 xor bx, bx mov cx, sourceText.size mov dx, sourceText int $21 ;HIDING_OFF ; Wait for keystroke xor ax, ax int $16 ; Exit to DOS int $20 ;HIDING_ON sourceText: file 'auto.asm' sourceText.size = $ - sourceText I have my brain so burned that I simple can't get it done. If someone wants to implement it I'm posting my unfinished code to provide an idea of how to do it but it doesn't work at this time... Code: macro InsertSourceCode labelName, sourceFile { local higing, index, base, start, fileSize, char, strChar, i, pStr, strLen labelName: virtual at 0 file sourceFile fileSize = $ end virtual index = -1 hiding = 0 char = 0 while fileSize > index while fileSize > index virtual at 0 rb 2 rb 2 start = $ store byte $ at 1 db ";HIDING_OFF" store byte $-start at 3 start = $ store byte $ at 0 db ";HIDING_ON" store byte $-start at 2 text = $ file sourceFile:index load pStr byte from hiding load strLen byte from hiding+2 i = 0 while (fileSize > index+i) & (strLen > i) load strChar byte from pStr+i load char byte from text+index+i i = i + 1 if strChar <> char index = index + i break end if end while if strLen = i if hiding hiding = 0 base = index index = index - base else hiding = 1 end virtual break end if end if ; Skip line while (char <> 10) & (fileSize > index) load char byte from text+index index = index + 1 end while end virtual end while file sourceFile:index, fileSize-index-1 end while file sourceFile:index-1 labelName#.size = $ - labelName } [edit]Better I'll explain a little what I'm trying to do. The first thing is to check if the first word of the source line is the opposite of the current hiding (it searches for ";HIDING_ON" when hiding is 0 and searches for ";HIDING_OFF" when hiding is 1). If the search is successful then if the previous state was hiding off then it's set to on and breaks the while loop to write from a base displacement to the actual index (the current source it's a little far of this because I messed it up ) and enters to the loop again. If the string searching is for ";HIDING_OFF" then there is a base change and index correction but the while loop keeps working without interruption because switching to off (the default state) serves as start point for source "dumping". Well, more or less that is my idea of how to get this work[/edit] |
|||
02 Jan 2007, 00:00 |
|
f0dder 02 Jan 2007, 08:26
|
|||
02 Jan 2007, 08:26 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.