On Tue, Sep 02, 2014 at 07:13:03PM -0600, Kevin Keith wrote:
They avoid
self-modifying code, in cases where there are hardware or
religious reasons to do so.
Forgive my slowness, but I've having a hard time seeing how this would
work. Could you point me to any examples?
The example that pops in my head (even though it doesn't make sense on
a mainframe with no graphics hardware) is setting the "write" mode for
drawing on a graphics screen. So you do whatever math it takes to get
it down to a register full of bit(s) that you want to put into screen
memory using either an OR or XOR or MOV instruction (or local equivalent).
With self-modifying code you'd modify the code in-line (whenever the
write mode is changed), but that could cause unpleasantness if the CPU
has a prefetch queue or cache weirdness or read-only (or execute-only)
code space. And even if not, some people think it's morally wrong.
So instead you either maintain the modified opcode in a variable, or
else keep a pointer to one of three different constant opcodes, and
issue XCT/EX/etc. using that variable (or pointer) when the time comes.
So your main code path is never touched, but you can substitute the
correct opcode as needed.
Honestly, it doesn't come up much, but it's absolute magic when you
do need it. And as I said, on the IBM mainframes, it's the only way
to insert a variable count into a MVC/CLC/TR/TRT/etc. instruction
(I think MVCL etc. came in later models only? or there's some other
reason why you wouldn't always use it, that I've forgotten).
John Wilson
D Bit