flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Methods to reduce source code characters?

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 23 Nov 2010, 08:53
Many contests ask for smallest source code characters as a winning metric. I know assembly language has a snowball's chance in hell of competing with scripting languages in this regard. Anyhow, I'd like to address the problem: Which methods can be used to compact the source code?

! fix EQU ; because many are needed

M ! MOV ; for common instructions

Is there a way to create a recursive macro to put multiple instructions on one line?
Code:
; note: extra white space for readability
macro A [B] {common
  match C|D,B \{
    C
    A D
  \}
}    
...was my first try, but FASM doesn't do recursive macro invocation.

Any other ideas?

Might create a tool to analyze source code and produce smallest compaction. And you thought assembly was hard to read already. Laughing

Here I'll collect a list of example contests:
http://stackoverflow.com/questions/2527477/code-golf-connecting-the-dots/

...to be continued...

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup


Last edited by bitRAKE on 23 Nov 2010, 09:52; edited 2 times in total
Post 23 Nov 2010, 08:53
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 23 Nov 2010, 08:58
Actually I prefer more readable source, rather than smaller. I can type very fast, but my memory is short, so after several months I want to understand the program I wrote myself. Smile
Post 23 Nov 2010, 08:58
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Frank



Joined: 17 Jun 2003
Posts: 100
Frank 23 Nov 2010, 09:04
UNTESTED: Compress the source (zip, rar, whatever), convert the result into a single 'db' line, and decompress it with a macro at assemble-time.
Post 23 Nov 2010, 09:04
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 23 Nov 2010, 09:26
This is for coding contests.
I know it's not practical.

Need to send code directly to FASM. It might be possible to write a very small decompression algorithm in FASM syntax:
Code:
dq $XXXXXXXXXXXXXXXX,...
i=$
rb ?
j=$
while i>0
 if ?
  i=i-1
  load b byte from i
 end if
 ...
 j=j-1
 store byte c at j
end while    
...yeah, that would be well for larger sources. Before compression they would benefit from the other direct techniques - preprocessor type.

Edit: that wouldn't work. the compressed code needs to be assembled and the assembler can't do that with a single execution. Decompression would just generate the source code and not assembler it.
Post 23 Nov 2010, 09:26
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 23 Nov 2010, 10:39
bitRAKE wrote:
Is there a way to create a recursive macro to put multiple instructions on one line?
The trick was described here (or here in more detail.
There is also this tweak of fasm's core to allow multiple instructions in a row, but I guess you aim at standard fasm syntax here...
Post 23 Nov 2010, 10:39
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 23 Nov 2010, 10:58
Very nice,
Code:
macro A {
 macro B [C] \{ common
  match D|E,C \\{
   A
   D
   B E
  \\}
 \}
}
A

B cdq|xchg eax,ecx||    
Post 23 Nov 2010, 10:58
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 24 Nov 2010, 19:54
bitRAKE,

m equ mov can give you another idea. Measuring program by its source size is like measuring seam by length of needle used to sew it.
Post 24 Nov 2010, 19:54
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 30 Nov 2010, 22:38
Never tried Octasm?
Post 30 Nov 2010, 22:38
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.