Echo recreation in assembly review.
I am trying to win a bet with a friend of mine on whos "echo" recreation is more efficient. Executable size also matters but pure raw speed is what is important.
This really isn't a "help me" kind of question but more of a "any ideas for improvement" kind of question. He is making his echo recreation in C and I am making mine in 64-bit assembly using the nasm assembler. We both wanted to know if the GCC compiler makes programming in assembly pointless. The code compiles into a "1.9 KB" executable and uses a total of roughly "2 KB" of RAM. That's pretty darn small to me. I did reference some C libraries however I made sure with him that doing so would be acceptable. Code:
|
Quote:
|
|
firstfire, that isn't a link.
My KINGDOM for an assembler that would give you the cycle counts for each instruction after it assembles the program! David, could I please ask you to comment your code line by line, since I am unfamiliar with the Linux environment ?, i.e. there's a lot I don't understand up there. I have been an asm freak for a long time, but it's been a while since I've done this sort of thing. May I ask you how you picked up 64-bit asm? Are there any tuts on the web? (NOT software manuals from Intel etc. , I can't learn from those. I'd LOVE to learn from you, if you're willing to hold my hand a little :) Thanks! :) |
Quote:
|
Oh and by the way, you can replace "mov esi,0" with "xor esi, esi" in .start - (I bloody well HOPE that's an instruction) - that'll make it a wee bit faster, I think!
|
Quote:
Anyhow this is the updated code. I suck at documentation so hopefully you should get the gist of it: Note that this code is considered "tainted" or "dangerous" because it doesn't follow the standard GCC guidelines for assembly. Or at least according to the friend I was talking about earlier. I would be more than happy to help you out in an assembly related problem but I am no expert by any means so.... yeah. :-) Code:
|
How about ditching the C library altogether, and using only the write() syscall? To write to standard output using nothing but kernel-provided syscalls, set eax=4, ebx=1, ecx=pointer, edx=length, and use int 0x80. The call will clobber the registers (meaning their values will be random after the call).
Here is a 32-bit echo that compiles to a 404-byte executable file. It is nowhere near optimal, as it can be trimmed further quite a bit. I left only minimal comments into it. It uses no stack or heap at all (on top of what the kernel sets up and uses itself), only two bytes of static data and 88 bytes of code. Code:
global _start Code:
nasm -felf32 -o echo.o echo.asm |
Quote:
Made my day. |
Quote:
|
Quote:
As a punishment, here is more code: Code:
global _start Now this one is as ugly as the posterior opening of a bird of prey, and as hacky as a rabid barbarian on mushrooms. But it should work, even for very large command line argument lists. (Up to kernel limits for me.) What I am really interested in, is how are you going to measure the time taken? Wall clock? CPU cycles? Normal use, with just a few parameters, or with a huge parameter list? I would personally first agree on a suitable test set, then run it a few dozen times to get rid of outliers (runs where other stuff running on the machine slowed the run down). I'd pick either the minimum time, or the most typical time. Good luck, |
Quote:
|
What kind of a register is r12d? Is it any relation to r12?
Sorry to sound like a FOOL, but I thought it's better to know, and get my doubts cleared up than simply REMAIN a fool. (I've never even *installed* a 64-bit Linux, let alone programmed in 64-bit asm!). I have many more questions about the logic of the program, but I'll save those for later... David, can I send you an email through this site? I already sent you a friend request, but I'd like to meet up with you on video chat, if that's possible? :) Which country are you in, btw? Nominal Animal, since you're in Finland - are you a member of the demoscene? |
Quote:
I visit this site all the time so a PM would be just fine. I added your friend request. Once again I suck at documentation so I am sorry for the confusing logic. I actually presumed it was quiet readable but strings in nasm can be a little confusing. I actually thought the Intel and AMD (not AS good) manuals were a godsend but then again I have a LOT of programmming experience. The only thing I regret about switching to linux is a lack of "practical" examples for GUI work through XORG comparable to http://win32assembly.online.fr/tutorials.html I would love to create games in assembly using nasm. Its very rare to find decent assembly programmers. Even the assembly GCC outputs disturbs me but that is a completely different topic. I always thought I was some sort of mental masochist to enjoy assembly programming and learning as many languages as I can. Vielleicht bin ich rechts :-) This should hopefully explain your confusion about r12d. There are several more registers that I don't use to remain as compatible with older processors as possible. Code:
|
Quote:
I'm sending you a message through this site, check your messages. Quote:
You are not Mad at all! :) I would love to do the exact same thing, but a full 3D game in Asm is just TOO hard a proposition! You should look into the demoscene - Google it and read the Wikipedia link, that'll tell you everything. Go to www.pouet.net for a site where demosceners hang out. Quote:
Actually it didn't - I repeat my question, is it a 32-bit register? What does "extension" mean? |
All times are GMT -5. The time now is 11:03 AM. |