flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Main > fasm vs fasmg: minimal program text

Author
Thread Post new topic Reply to topic
Grom PE



Joined: 13 Mar 2008
Posts: 113
Location: i@grompe.org.ru
fasm vs fasmg: minimal program text
Just for fun, write the smallest possible source code that, when assembled, produces the exact lyrics of the 99 bottles of beer song.

Output should be 11885 bytes, MD5: 6805cea174ee0ff44092d0d7cf6dfa8f.

My result is 300 bytes for fasm:

Code:
e fix equ
w e ' on the wall'
rept 100 n:0{reverse
b e `n
c e b
s e 's'
match=n,1\{s e ''\}match=n,0\{b e 'no more'
c e 'No more'\}v e ' bottle',s,' of beer'
x e v,w,'.',10
if $
db 'Take one down and pass it around, ',b,x,10
end if
db c,v,w,', ',b,v,'.',10}db 'Go to the store and buy some more, 99',x

and 303 bytes for fasmg:

Code:
w=' on the wall'
rept 100
rept 1,n:100-%
b=`n
c=b
s='s'
if n=1
s=''
else if n=0
b='no more'
c='No more'
end if
v equ ' bottle',s,' of beer'
x equ v,w,'.',10
if $
db 'Take one down and pass it around, ',b,x,10
end if
db c,v,w,', ',b,v,'.',10
end rept
end rept
db 'Go to the store and buy some more, 99',x

Line endings are one character only, LF. The last line doesn't have the line ending.
Can you make it smaller? Which assembler will win in the end?


Description: 99 bottles of beer song in 300 bytes for fasm, 303 bytes for fasmg
Download
Filename: fasm_vs_fasmg.zip
Filesize: 615 Bytes
Downloaded: 111 Time(s)

Post 17 Sep 2016, 11:24
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6677
Location: Kraków, Poland
Two minor tweaks can make your fasmg version shorter:

Code:
w=' on the wall'
rept 100 
rept 1,n:%%-%
b=`n 
c=b 
s='s' 
if n=1 
s='' 
else if~n
b='no more' 
c='No more' 
end if 
v equ ' bottle',s,' of beer' 
x equ v,w,'.',10 
if $ 
db 'Take one down and pass it around, ',b,x,10 
end if 
db c,v,w,', ',b,v,'.',10 
end rept 
end rept 
db 'Go to the store and buy some more, 99',x

Post 17 Sep 2016, 13:57
View user's profile Send private message Visit poster's website Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 113
Location: i@grompe.org.ru
Ah, very nice! 300 bytes for fasmg, it's a tie now!
Post 17 Sep 2016, 14:07
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15312
Location: Bigweld Industries
One less byte for the fasm version. Change in line 4 only:

Code:
e fix equ
w e ' on the wall'
rept 100 n:0{reverse
b e`n
c e b
s e 's'
match=n,1\{s e ''\}match=n,0\{b e 'no more'
c e 'No more'\}v e ' bottle',s,' of beer'
x e v,w,'.',10
if $
db 'Take one down and pass it around, ',b,x,10
end if
db c,v,w,', ',b,v,'.',10}db 'Go to the store and buy some more, 99',x

Post 17 Sep 2016, 15:00
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15312
Location: Bigweld Industries
Two more bytes excised from the fasm version. Remove the escaping backslashes from the opening {

Code:
e fix equ
w e ' on the wall'
rept 100 n:0{reverse
b e`n
c e b
s e 's'
match=n,1{s e ''\}match=n,0{b e 'no more'
c e 'No more'\}v e ' bottle',s,' of beer'
x e v,w,'.',10
if $
db 'Take one down and pass it around, ',b,x,10
end if
db c,v,w,', ',b,v,'.',10}db 'Go to the store and buy some more, 99',x

Post 17 Sep 2016, 15:03
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6677
Location: Kraków, Poland
A bit more squeezed fasmg version:

Code:
t=''
w=' on the wall'
rept 100
b='no more'
c='No more'
rept %%-%,n
b=`n
c=b
end rept
s='s'
if %=99
s=''
end if
v equ ' bottle',s,' of beer'
x equ v,w,'.',10
db t,c,v,w,', ',b,v,'.',10
t equ 'Take one down and pass it around, ',b,x,10
end rept
db 'Go to the store and buy some more, 99',x

Also, '.' can be replaced with 46 to cut two more bytes off both fasm and fasmg version.
Post 17 Sep 2016, 20:24
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15312
Location: Bigweld Industries
fasm 293 bytes:

Code:
_ fix equ
w _ ' on the wall'
rept 100 n:0{reverse
b _`n
c _`n
s _ 's',
match=n,1{s _\}match=n,0{b _ 'no more'
c _ 'No more'\}v _ ' bottle',s#' of beer'
x _ v,w,46,10
if $
db 'Take one down and pass it around, ',b,x,10
end if
db c,v,w,', ',b,v,46,10}db 'Go to the store and buy some more, 99',x

Post 17 Sep 2016, 21:18
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15312
Location: Bigweld Industries
fasm 291 bytes:

Code:
_ fix equ
w _ ' on the wall'
rept 100 n:0{reverse
b _`n
c _`n
s _`s,
match=n,1{s _\}match=n,0{b _ 'no more'
c _ 'No more'\}v _ ' bottle',s#' of beer'
x _ v,w,46,10
if $
db 'Take one down and pass it around, ',b,x,10
end if
db c,v,w,', ',b,v,46,10}db 'Go to the store and buy some more, 99',x

Post 17 Sep 2016, 21:34
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6677
Location: Kraków, Poland
fasmg, 283 bytes:

Code:
t=''
w=' on the wall'
rept 100
b='no more'
c='No more'
rept %%-%
b=`%
c=b
end rept
s='s'
if %=99
s=''
end if
v equ ' bottle',s,' of beer'
x equ v,w,46,10
db t,c,v,w,', ',b,v,46,10
t equ 'Take one down and pass it around, ',b,x,10
end rept
db 'Go to the store and buy some more, 99',x

Post 17 Sep 2016, 22:08
View user's profile Send private message Visit poster's website Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 113
Location: i@grompe.org.ru
Used Tomasz's amazing trick with double rept to shorten fasm version to 286 bytes:

Code:
_ fix equ
w _ ' on the wall'
rept 100 m{b _ 'no more'
c _ 'No more'
rept 100-m n{b _\`n
c _ b\}s _`s,
match=m,99{s _\}v _ ' bottle',s#' of beer'
x _ v,w,46,10
if $
db 'Take one down and pass it around, ',b,x,10
end if
db c,v,w,', ',b,v,46,10}db 'Go to the store and buy some more, 99',x

Post 18 Sep 2016, 07:47
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1904
Post 23 Sep 2016, 17:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15312
Location: Bigweld Industries

DOS386 wrote:
http://board.flatassembler.net/topic.php?t=5411

That one doesn't count because it is not canonical. But the above solutions can easily be converted to one-liners.
Post 23 Sep 2016, 18:18
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.