Re: A85: line


[Prev][Next][Index][Thread]

Re: A85: line




Sure.  Self-modifying code is far from "good" programming practice
today, when memory is cheap and processors are ultra-fast (besides, with
high-level programming languages it becomes nearly impossible with
restrictions).  But the TI-85 is very much like a computer of old
(limited memory, 8-bit micro).  So self-modifying code is almost an
essential art in saving lots of space.  The idea of self-modifying code
is to change executable code much like you alter data or variables (sort
of like a code segment vs. a data segment).  So, say you have HL
pointing to a location in your "code segment" and you have A, the
accumulator, equal to an opcode that you wish to load into [HL].

  ld hl, CodetoModify
  ld a, $cd                  ;some op-code, a CALL on the Z80
  ld (hl), a
     :
     :
CodetoModify:
  jp Location

This will effectively change the JP to a CALL.  This in no way
illustrates a good use of self-modifying code, but certainly addresses
the concept.  I think my BGLIB for Rigel uses some self-modifying
code...maybe that can offer more practical examples.  Hope this helps.

Ben

Michael Pearce wrote:
> 
> can someone explain the whole self modifying code thing.
> 
> -mike pearce
> 
> On Wed, 06 May 1998 03:24:18 +0200, you wrote:
> 
> >
> >At 13:23 1998-05-05 -0400, you wrote:
> >>
> >>speaking of FLINE, does anyone have the source to it that's willing to
> >>share it with an 82 programmer who needs it to complete a port?  i know
> >>that it'll need to be reconfigured for a 96 pixel screen, but i just need
> >>the source.
> >
> >I'm not sure the source would help you, because I don't think it
> >can be ported to the 82 without losing quite some speed (because
> >of the video device thing). It uses selfmodifying code quite
> >much, so don't remove any 'add a,0'...
> >


Follow-Ups: References: