Warning: Do not use this code in production environments or as a drop-in replacement for your other Unix utilities.

On Sunday, I thought about making an assembly program to learn assembly by doing. I thought of the cat program because I thought it wouldn't be too difficult. It took until the next day that I got it to work.

Then I thought: What if I try to make other Unix programs?
So far, I have made cat and mkdir, but the mkdir source is similar enough that I also got it to assemble to touch, rm, and rmdir. They don't have any command-line arguments, so you can't execute something like

Code:
rm -rf /

or

Code:
rm -r folder-with-files/


The repository is located on the Github repo, so suggestions and feedback are welcome! All you need to install is NASM, GNU ld, and Make.
Minor update:
Add the -f command to suppress errors on rm, rmdir, touch, and mkdir.
Made it so mkrndirfile/ doesn't need one assembly file for each binary.

I plan to get back to work on this, as my work was halted due to school and waning willpower.
Kind of major update:
I got the idea of removing the section headers in the executables because they take up over 100 bytes! I made strip-secthead, which does this for me. Here is the size difference I achieved:

Code:
cat:            464 bytes -> 256 bytes
mkdir, touch:   424 bytes -> 215 bytes
rmdir, rm:      424 bytes -> 210 bytes
strip-secthead: 608 bytes -> 331 bytes

DO NOT use this on non-executable files, because they will be corrupted, and there are almost no safeguards.
Update:
I deprecated strip-secthead and the beta of head. Instead, I made my own ELF header and embedded the exit code in the header. This is the current size listings:

Code:
cat: 232 bytes
mkdir, touch: 190 bytes
rmdir, rm: 185 bytes

I am planning to make another program soon, but that is TBD because I want to think of one that will challenge me.
Yet another update:
I made yes, and I reduced the program sizes even further.

Code:
cat: 210 bytes
mkdir, touch: 150 bytes
rmdir, rm: 145 bytes
yes: 162 bytes

No, yes didn't challenge me, but I thought it would be quick and painless to do. As always, my changes are welcome on Github (listed above) so you can use the code if you want.
Update:
I made clear. It may or may not work on your terminal, so you should run this command and edit clear.asm appropriately. With the default configuration, it takes up 137 bytes.

Code:
clear | xxd


I also made an "experimental" port of the current programs to the Linux X32 ABI. Here is a comparison of the sizes of the programs.

Code:
cat:          210 -> 189       
clear:        137 -> 117
mkdir, touch: 150 -> 126
rmdir, rm:    145 -> 121

Note: You will probably need to edit your GRUB configuration for these to work.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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

 

Advertisement