News for hackers. Stuff that matters.
Re:Reverse-engineering the conditional jump circuitry in the... by shadowofneptune on Monday January 23, 2023 @03:51PM (#34494854)
Have address calculations been covered yet? Those are pretty complex on the '86.

Alternatively, the 'rep' prefix would be interesting.

Re:Reverse-engineering the conditional jump circuitry in the... by peterfirefly on Monday January 23, 2023 @04:05PM (#34495026)
I vaguely remember that it had trouble remembering more than one prefix past an interrupt -- so if you wanted to combine REP with a segment override prefix you should put the REP first, then the segment override prefix, then the string instruction... and then some conditional jump stuff that jumped back to the REP if CX != 0.

So basically:

    repeat: rep
            cs:
            scasb
            jcxz   done
            jmp    short repeat
    done:
Re:Reverse-engineering the conditional jump circuitry in the... by shadowofneptune on Monday January 23, 2023 @04:44PM (#34495512)
Micheal Abrash's book covers this. May just be better to swap out the segment registers at that point though.
Re:Reverse-engineering the conditional jump circuitry in the... by kens on Monday January 23, 2023 @04:04PM (#34495003)
Those are good suggestions. I'll see if I can figure out how to explain them :-)
Re:Reverse-engineering the conditional jump circuitry in the... by rot13xor on Monday January 23, 2023 @06:57PM (#34496931)
I always wondered why x86 has LEA when its functionality can be replicated by ADD. It has to do with LEA and ADD being able to run in parallel because LEA uses a separate ALU in the address calculation part of the chip, not the main ALU.
Re:Reverse-engineering the conditional jump circuitry in the... by shadowofneptune on Monday January 23, 2023 @07:31PM (#34497286)
LEA only got more powerful in later models as the restraints on registers were removed and more addressing modes got added. Now it can do several additions and a multiplication in a single operation. Reusing that memory hardware/instruction format is a clever ISA decision.
Re:Reverse-engineering the conditional jump circuitry in the... by Gordonjcp on Tuesday January 24, 2023 @03:54AM (#34501225)
Wait, so if you were imaginative enough with how you use registers to calculate addresses you could abuse LEA as a DSP MAC (multiply/accumulate) instruction?
Re:Reverse-engineering the conditional jump circuitry in the... by moefh on Tuesday January 24, 2023 @04:15AM (#34501376)
Compilers do it all the time, for example GCC compiles "x*4 + y" to a single LEA instruction: https://godbolt.org/z/TvdW5sK4b
Re:Reverse-engineering the conditional jump circuitry in the... by Gordonjcp on Tuesday January 24, 2023 @09:03AM (#34503635)
Aha, playing with it, it looks like the multiply is just a shift because if you try to do anything other than powers of two it has to break it down into more instructions.

Still clever, though. I guess it's to make it easier and quicker to index over words or multiples of words?

Re:Reverse-engineering the conditional jump circuitry in the... by rep_lodsb on Tuesday January 24, 2023 @09:40AM (#34504111)
* * *
Re:Reverse-engineering the conditional jump circuitry in the... by peterfirefly on Tuesday January 24, 2023 @06:52AM (#34502453)
The system might choose to use relocations for LEA and not for ADD -- this is of course not relevant for stack relative addressing and struct member addressing on the heap. I think I ran into this when coding assembler for DOS in the late 80's.

LEA also gets the "register + offset" thing done in a single instruction instead of two (MOV + ADD). It's also really easy for both assembler programmers and (dumb) compilers.

The "run in parallel" stuff is you looking at modern(ish) CPUs and thinking the original 8086 looked anything like that inside.