PDA

View Full Version : What can YOU do with 256 Bytes??



MrWizard
07-18-2002, 04:31 PM
This site is dedicated to people who write program that are less than or equal to 256 bytes! Some of this stuff is simply amazing. For instance, look what one guy did...."out of control"...

http://www.256b.com/demo.php?demoId=225&PHPSESSID=7c6f4afed486d0499e65bf0ad18ac43a

So what can YOU do with 256 Bytes?

Betazep
07-18-2002, 04:37 PM
Impressive.

ygfperson
07-18-2002, 05:16 PM
http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html

here's a short dos program:


mov ax,0x4C00
int 0x21


and a short linux one:


mov ax,1
xor bx,bx
int 0x80

Hillbillie
07-18-2002, 06:07 PM
I've got a bootloader that is exactly 512 bytes I wrote. ;) (Compuboy, don't worry. It's one that I hacked up one day - it's not yours.)

ygfperson
07-18-2002, 08:22 PM
theoretically you can make a 1 byte file:


RET

assemble that into a com file and run that, and it should work properly.

//edit: after actually going into that site and checking it out... that is amazing. it's practically 3d, it's somewhat complicated, and it takes 256 bytes?!...
awesome.

civix
07-18-2002, 09:30 PM
neat-o!! I doubt i could make anything under 100kb even if i tried...

Xmevs
07-19-2002, 08:21 AM
ditto...


maybe in a couple of years, though...

Fordy
07-19-2002, 08:40 AM
Its pretty limited in what you can do (com files just hold the code, no import info or resources), but what some of them have done there is really cool..........

MrWizard
07-20-2002, 05:19 AM
Originally posted by civix
neat-o!! I doubt i could make anything under 100kb even if i tried...

Certainly not with any high level language ;)

mithrandir
07-20-2002, 07:34 AM
doubleanti eat your heart out!

Fordy
07-20-2002, 08:30 AM
Originally posted by civix
neat-o!! I doubt i could make anything under 100kb even if i tried...

Well here you go.......this produces a Hello World executable that's 26 bytes....that should start you off!!!!




#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
char szProgName[] = "Small.COM";
unsigned char MySmallProg[] =
{0xBA,0x0E,0x01,0xB4,0x09,0xCD,0x21,
0xB4,0x4C,0x32,0xC0,0xCD,0x21,0x00,
0x48,0x65,0x6C,0x6C,0x6F,0x20,0x57,
0x6F,0x72,0x6C,0x64,0x24};
ofstream os(szProgName,ios::binary | ios:: out);
os.write((const char*)MySmallProg,26);
os.close();
system(szProgName);
return 0;
}

ygfperson
07-20-2002, 05:36 PM
you call that slim? you're wasting more than 15 percent of your space! economize, man! :D

#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
char szProgName[] = "Small.COM";
unsigned char MySmallProg[] =
{0xBA,0x08,0x01,0xB4,0x09,0xCD,0x21,0xC3,
0x48,0x65,0x6c,0x6c,0x6f,0x2c,0x20,0x77,
0x6f,0x72,0x6c,0x64,0x21,0x24};
ofstream os(szProgName,ios::binary | ios:: out);
os.write((const char*)MySmallProg,26);
os.close();
system(szProgName);
return 0;
}

beat that!

Xterria
07-20-2002, 07:53 PM
ok



#include <stdlib.h>
int main(void)
{
system("echo Hello World");
return 0;
}


i love 'em.

Fordy
07-20-2002, 08:05 PM
Hmm....I didnt think you could substitute the dos exit call (int 21h....ax = 04C00h) with a simple ret......

I must admit that my experience of DOS assembly is small (I dont have much need for it as all my assembly noodling is for Win32) but is this acceptable?...Running the code through a debugger, I noticed that as expected, the ret forced the code to jump to the address on the top of the stack....which sent it to an int 20h at the start of the code seg...which then terminated the program.......

I thought DOS programs had to explicitely call DOS to end the program with ax as 04C00h...........I understood that this caused DOS to reload the command interpretor......hmm......

Any info on this would be nice


....Oh...and btw, your code still outputted 26 bytes as you failed to edit the ofstream::write() func :p :p....I can get it down to 24bytes, but if I stick to the DOS Exit Program method I think I'm stuck at that :)

ygfperson
07-20-2002, 08:41 PM
in exe files, you can also use

INT 0x20

to exit.
using the

mov ax,0x4c00
int 0x21

method works fine in all cases, and it returns a value via al.

i suppose you could print hello, world! in other languages. or you could point dx to 100 and claim the resulting gibberish is timbukanese for "Hello, world!" :D

Fordy
07-20-2002, 08:44 PM
Hmm...didnt know about the int 20h thing.......cool :)

ygfperson
07-20-2002, 09:46 PM
if you were even more desperate for space, i reckon you could simply skip the exit altogether and hope that the next few instructions in memory will do it for you...

but probably not. :D

Fordy
07-21-2002, 02:15 AM
Originally posted by ygfperson
if you were even more desperate for space, i reckon you could simply skip the exit altogether and hope that the next few instructions in memory will do it for you...

but probably not. :D

Well as all the data and code are together in COM files, I would end up executing the Text "Hello World"...which basically looks like it will do nothing good :)

face_master
07-21-2002, 02:27 AM
These 2 programs posted are quite slow. Do you usually do it this way to save on space?

Fordy
07-21-2002, 02:56 AM
Originally posted by face_master
These 2 programs posted are quite slow. Do you usually do it this way to save on space?

They are probably slow for a few reasons....They will be slow if you run them through the C++ program as it uses system() which is slow as sludge anyway....

Also I guess that as windows doesnt allow programs to run interupts (the way dos progs print to screen, manage disks etc), it intercepts these calls and interprets them into something it prefers - either low level access the windows way, or in the case I guess the API call WriteConsole()......I can only guess this will make these progs slower than a normal Hello World that accesses the API funcs to begin with

I also read that COM files used to take up more memory space than some exe files when run in DOS (even though they are smaller on disk) but I dont have a clue if its the same run on windows....:confused: