flat assembler
Message board for the users of flat assembler.
Index
> Main > Batch file doubling as a fasmg source |
Author |
|
Tomasz Grysztar 09 May 2019, 11:12
Recently I came up with this fun little trick to make a batch file that could also be assembled with fasmg, and when executed would run fasmg to assemble itself:
Code: @echo off goto batch end if macro @echo off if 0 end macro virtual at 0 digits:: n = %t / 50 while n d = '0' + n mod 36 if d > '9' d = d - '0' - 10 + 'a' end if n = n / 36 db d end while count = $ end virtual repeat count load d byte from digits:count-% display d end repeat macro ?! any& end macro :batch fasmg %~f0 nul -n |
|||
09 May 2019, 11:12 |
|
Tomasz Grysztar 09 May 2019, 13:33
revolution wrote: Is this to save having a second file on disk? |
|||
09 May 2019, 13:33 |
|
edfed 13 May 2019, 07:40
very cool feature, i never use os capabilities. maybe it's time to...
This trick makes possible to postcompile generated sources , i like it. |
|||
13 May 2019, 07:40 |
|
d469964 20 May 2019, 01:18
I think you overcomplicate things:
Code: @rem: if 0 @fasmg "%~f0" nul @exit end if virtual at 0 digits:: n = %t / 50 while n d = '0' + n mod 36 if d > '9' d = d - '0' - 10 + 'a' end if n = n / 36 db d end while count = $ end virtual repeat count load d byte from digits:count-% display d end repeat Works perfectly with fasm & fasmg. |
|||
20 May 2019, 01:18 |
|
revolution 20 May 2019, 07:48
d469964 wrote: I think you overcomplicate things: Is there a way to also make it work with bash? |
|||
20 May 2019, 07:48 |
|
Tomasz Grysztar 20 May 2019, 08:03
d469964 wrote: I think you overcomplicate things Your variant is of course great at being concise, but I designed mine to be able to accomodate existing source code and existing batch script and have them cleanly separated without a risk of having a command within the batch portion that could be misinterpreted by the assembler. In your case inserting a script containing a command like "if errorlevel" would break the assembly. |
|||
20 May 2019, 08:03 |
|
d469964 20 May 2019, 17:18
d469964 wrote: In your case inserting a script containing a command like "if errorlevel" would break the assembly. It's not a problem: Code: @rem: if 0 @fasm "%~f0" nul @if errorlevel 1 ( echo Compilation error! pause ) @goto :EOF end if |
|||
20 May 2019, 17:18 |
|
Tomasz Grysztar 20 May 2019, 17:26
This was my point exactly - you needed to check and modify the batch commands to ensure that they are written in way that does not cause problems. The framework I proposed should allow to take a script as-is and not worry about possible interference.
|
|||
20 May 2019, 17:26 |
|
d469964 20 May 2019, 19:30
Quote:
I'm not a Linux guy and create only this (bash only): Code: echo=0 if echo; then fasm "$0" exit fi end if and this (both bash and batch, but print one line of garbage): Code: rem=""; : ' @rem: if 0 @fasmg "%~f0" nul @exit ;' fasmg "$0" exit end if |
|||
20 May 2019, 19:30 |
|
Grom PE 21 May 2019, 06:37
Thankfully the semicolon is both a comment in fasm and ignored in batch, so I was able to come up with a polyglot file with batch and fasm source completely separate:
https://github.com/grompe/kbdasm/blob/e12b8c1a41f36ecbf8d5486af1716226233e72c2/diskbd.bat |
|||
21 May 2019, 06:37 |
|
rugxulo 21 May 2019, 17:42
I'm no expert, but this can also be done in Perl, Ruby, etc. with .BAT. (Also, Bash shell scripts can have here docs or whatever.)
|
|||
21 May 2019, 17:42 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.