Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!athena.mit.edu!tada From: tada@athena.mit.edu (Michael J Zehr) Newsgroups: comp.arch Subject: Re: Self-modifying code Summary: example code Message-ID: <15000@bloom-beacon.MIT.EDU> Date: 10 Oct 89 21:21:35 GMT References: <1080@mipos3.intel.com> <4415@bd.sei.cmu.edu> <33334@ames.arc.nasa.gov> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: tada@athena.mit.edu (Michael J Zehr) Organization: Massachusetts Institute of Technology Lines: 20 I found an example of self-modifying code back in the middle ages (c. 1981) in the operating system on a Z-80 chip. As i recall, the Z-80 had bit set, clear, and test op-codes which needed an assembly-time bit number rather than using a register to determine which bit to set/clear/test. it took less space to determine the right bit and load the opcode (i think a shift would give you the opcode for a bit, or maybe shift and add an offset) into the right place in memory and then execute it. the other option was to have a 8 branch statements. but the way to really save space was to call the routine with a parameter which indicated which operation (set, clear, test) and after computing the opcode to indicate the right bit, also select the opcode to indicate the kind of operation and load that into memory and execute it. *very* kludgy, but it took a surprisingly small amount of space with only a small penalty in speed. -michael j zehr