Self-modifying code

Roland Conybeare conybear at moncsbruce.oz
Mon Jul 18 13:51:45 AEST 1988


>From article <752 at cernvax.UUCP>, by hjm at cernvax.UUCP (hjm):
> As a final note, why is it 'clean' to alter a jump table and 'unclean' to 
> alter an inline constant (e.g. jmp @offset(r0) uses a value in memory as the
> address but mov (pc)+,#1234 which loads an immediate does so too)?  Why
> the subtle difference?  Any thoughts on the subject?
> 
> 	Hubert Matthews

I can see several reasons.

* the big, big reason for referring to code via pointers, and getting the effect
  of self-modifying code via such pointers, is that you make your changes
  independent of the size of the code.  Real SMC will only work when the new
  code is no larger than the old code.  I think this is a very restrictive
  assumption.

* when you alter a jump table (in C, at least) you are doing so within the 
  language, and can expect the compiler to understand you.  A language which
  allows you to modify instructions directly would of necessity depend strongly
  on the machine architecture to run these instructions.  Otherwise, why don't
  we all use Universal Assembly Language?

Roland Conybeare
conybear at moncsbruce.oz

  an instruction, like mov (pc)+,#1234 you are assuming that the change you
  make 



More information about the Comp.lang.c mailing list