4 ms·
This is a great article. I used it to optimize the code for a code golf puzzle our hackerspace made: http://codegolf.coredump.ch/challenges/asm-compass/ http://
by dbrgn 9y ago
This is a great article. I used it to optimize the code for a code golf puzzle our hackerspace made: http://codegolf.coredump.ch/challenges/asm-compass/ http://codegolf.coredump.ch/challenges/asm-compass/ If you want a challenge to reduce the binary size of a very simple program (= choosing instructions with smaller opcodes), give it a try :)
- userbinator 9y agoI've done a few challenges like that[1] but seeing that the smallest so far is over 300 bytes makes me think most of those 300 bytes are not actual code but program header overhead, because it should be doable in much fewer bytes of actual code. Once you've done these challenges a few times, you can easily estimate a rough size: The template is 48 bytes. Add 16 bytes for an [offset,char] table. Maybe another 30 bytes (let's be generous and round that up to 32) for code to pull the commandline parameter, do the indexing and template modification, write the output, and exit. 96 bytes of code. Add 64 bytes of minimal ELF headers[2] and you're still well below 200 bytes. I don't have an environment at the moment that doesn't do ELF files, so I just tried it with 16-bit DOS and ended up at... 95 bytes: https://pastebin.com/C7vDfFbR https://pastebin.com/C7vDfFbR I wasn't trying very hard so someone will probably find an even smaller version, and it was just for fun since it doesn't meet the rules anyway. [1] http://www.hugi.scene.org/compo/compoold.htm http://www.hugi.scene.org/compo/compoold.htm [2] http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...
- jsjohnst 9y agoELF binaries under 200b: 142 bytes: http://timelessname.com/elfbin/ http://timelessname.com/elfbin/ 45 bytes: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...
- dbrgn 9y agoThanks for the links! Most of the submitted approaches don't even mess with the ELF binary structure. But even if you don't do that, there's a lot you can learn by optimizing (sometimes doing something with more instructions instructions actually result in a smaller binary because of shorter opcodes). It was the first time I really messed around with x86 assembly and I learned a lot during the progress :) Edit: Wording Edit2: Also note that for this challenge you need to submit NASM assembly, and not the resulting binary. So you can't resort to hex editing the binary itself.
- colatkinson 9y agoI've been working on learning x86 ASM, and this was a fun challenge. Cool stuff.