Re: Jumping into middle of instruction




Bob Masta wrote:

mybwpp asked:

Can we categorize this technique of jumping into middle of
instructions, as 'self modifying code'?
No, SMC is a different story.
start:
; this works only in true RealMode!
cmp al,80h
jns L1:
mov word CS:[L2],9090h ;two NOPs
L1:
... ;put some code in here to avoid prefetched remains
mov ax...
add ax,cx
L2:
JC L3 ;this two bytes may become NOPS
...

How does Real Mode make a difference here?

You can't direct write to CodeSeg in protected mode.

I thought it only had to do with the processor architecture,
regarding the depth of the
prefetch queue and whether it was smart enough to know when to
invalidate the queue when you use short forward SMC.

Yes, but I encountered this prefetch issue also on modern CPUS.

On modern processors it's probably not a good idea to
depend upon a certain depth of prefetch queue, but in the
Olden Days (before CPUID) when there were only a few x86 CPUs and
they had known queue differences, you could identify the CPU by
its queue length. You modified code at known distances ahead,
and if the modifications were ignored you knew that those instructions
must have already been in the queue.

Right.
SMC is of rare use anyway, I use it only on video mode changes to
save on just minor different routines and make this 'variables'
to contants for speed reason.

To answer the OP, self-modifying code is anything that alters
the actual code. The jump-into-instruction leaves the code
unaltered, and just takes a different path through it.

Yeah.
__
wolfgang


.



Relevant Pages

  • Re: Jumping into middle of instruction
    ... SMC is a different story. ... invalidate the queue when you use short forward SMC. ... and if the modifications were ignored you knew that those instructions ... Scope, Spectrum, Spectrogram, FREE Signal Generator ...
    (comp.lang.asm.x86)
  • Re: moving data from one place to another in a text file
    ... Create a queue per thread. ... > parser as a dealer distributing cards to the multiple players. ... will always want to overclock as many CPUs as they can supply Liquid ... Java may well support multi-threading, but that does not mean that it ...
    (comp.lang.cobol)
  • Re: EnterCriticalSection
    ... The is a false assertion. ... You probably don't know that acquiring and releasing an uncontended lock involves the use of 2 interlocked RMW instructions and 2 memory barriers, one of which is very expensive. ... I am talking about an unbounded single producer/consumer wait-free queue that relies on the assertions made in the following paper: ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Best way to deal with long loops?
    ... bitten by a delay loop no longer taking any measurable time as CPUs ... On a too-fast processor, the queue will simply ...
    (alt.comp.lang.borland-delphi)
  • Re: [sched-devel, patch-rfc] rework of "prioritize non-migratable tasks over migratable
    ... I haven't had a chance to review your patch, so I am only responding to the comments in this thread. ... - there might have been other pending tasks (of equal prio) on this ... there are no other pending tasks on the queue that ... its affinity allows CPUs that can be used neither by ...
    (Linux-Kernel)