Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Yes, 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.


From the Github page: 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.


You really should have a look at the rust code this guy wrote. I would not call that last optimization type safe.


How so? The only unsafe part is the transmute which only saves 7 bytes anyways :P


Even 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.


LLVM currently does not optimize for size, so things like the small-integer push/pop trick aren't goign to happen.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: