back

by raphlinus·7d ago·view on hn ↗
I was curious about this and had a look. The code doesn't look much better than what a good C compiler might produce, and I found quite a few opportunities to optimize. It doesn't look much at all like the 8088 code I wrote when I was a teen. Among other things, so much pushing and popping.

Take the irow loop in vga12.inc[1] (of course I'm going to look at the graphics code). Each iteration does push di; rep stosb; pop di; add di, ROW_BYTES (and some other stuff). Why not save the push/pop and add (ROW_BYTES - count), which could be stored in a register (dx is free here)? Just the push+pop is 15+12 cycles.

[1]: https://github.com/jggonz/os8088/blob/1f2fae44180fadaf85368c...

1 comments
True, that piece can be optimized better, but quality of the assembly code in general is not far away from what I had been writing in 1993-96. Back then, push/pops in function prologues/epilogues were a sign of experienced assembly programmer who avoided register clobbering by using standard calling conventions.