Hacker News new | past | comments | ask | show | jobs | submit login

Looking through the repo, some of the assembler [1] looks odd:

    getShdwOfst:
        xor bh,bh
        mov bl,al
        mov di,bx
        shl di,1
        shl di,1
        shl d1,1
        ...
Why shift one bit at a time, like you would on a CPU like the 6502 with no multi-bit shift instructions? Was this hand-ported from some system without those?

[1]: https://github.com/lanceewing/agi/blob/main/src/CMGRAPHX.ASM...




It was hand-written for a system without multi-bit shift instructions.

8086 shifts were 1 bit at a time (2 cycles for a register shift.) or using cl for the count (8 cycles + 4 cycles/bit for a register shift).

constant multi-bit shifts were added in the 80186.


8088 did not have a barrel shifter, so multi-bit shifts would have been expensive and non-interruptible over multiple clocks. Perhaps game devs just avoided them out of habit.




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

Search: