4 ms·
That main() can still be improved... try this: push 1 pop eax mov edi, eax mov esi, 400008h push 7 pop edx syscall push 3ch
by userbinator 12y ago
That main() can still be improved... try this:
push 1
pop eax
mov edi, eax
mov esi, 400008h
push 7
pop edx
syscall
push 3ch
pop eax
xor edi, edi
syscall
It should be 10 bytes shorter.
- ekimekim 12y agoYes, but the point was that it could be done in rust, using rust's language features (type safety and so forth). Making your main inline assembly isn't really using the language very much.
- omega_rythm 12y agoYou really should have a look at the rust code this guy wrote. I would not call that last optimization type safe.
- the_mitsuhiko 12y agoHow so? The only unsafe part is the transmute which only saves 7 bytes anyways :P
- exprL 12y agoEven that is still type safe, just not portable. After all, every part of the memory is a collection of bytes (that is, a slice of u8) – whether you can access them is another story.
- userbinator 12y agoFrom the Github page: https://github.com/kmcallister/tiny-rust-demo https://github.com/kmcallister/tiny-rust-demo All of the machine code comes out of rustc. (Although all of the instructions that survive optimization went in as inline assembly.) So while his main() is written in (unsafe) Rust, he's basically using it as a macroassembler.
- taralx 12y agoLLVM currently does not optimize for size, so things like the small-integer push/pop trick aren't goign to happen.