How well optimized is my 32 bit NASM BASIC interpreter? #119526
Replies: 1 comment 2 replies
-
Nice! Programming in ASM can be satisfying, isn't it. ;) So what do you want to optimize? Speed of running? Size of the binary? What architecture are you targeting? As for the speed: I did not profile. But you can argue that the vast amount of processing is system call related (either the call itself or setting up the registers). Otherwhise, your program does not really need much memory and registers are fast. So, if you want to use this piece of code in a tight loop without the user in it, you should try to output less (to reduce interrupts), etc. For the size of the binary. I kind of don't want to be that guy but technically speaking you could probably reduce the size. The fallowing snippet reappears a lot in your code: ; Output the result
MOV EAX, 4
MOV EBX, 1
MOV ECX, EDI ; sometimes ESI
MOV EDX, 4
INT 0x80 So you could make that a function (without allocating a stack frame), then call it. There should not really be any performance penalty for that. A call is an unconditional jump and prefetchers on modern machines should be pretty good with those. Also the binary size is small, so it will likely be fully on the cache anyways. Branch prediction for unconditional jumps is trivial too and so the instruction pipeline should be full. If you spotted anything else, let me know. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions