Article View: comp.arch
Article #2586Re: Self-modifying codeREAD/NEW/FOLLOWUP
From: Don Stokes, GPO
Date: Sun, 15 Oct 1989 00:00
Date: Sun, 15 Oct 1989 00:00
37 lines
2382 bytes
2382 bytes
In article <15000@bloom-beacon.MIT.EDU>, tada@athena.mit.edu (Michael J Zehr) writes:
> 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.
>
I once saw a neat technique to get a bit mask from a bit number on a 6502
(eg plug in 4, get 16 out) - the routine went:
sta jump+1 ; Modify branch instruction offset
lda #$80 ; Bit 7 set
jump: bne jump ; This gets modified
lsr A ; Number of shifts depends on branch
lsr A
lsr A
lsr A
lsr A
lsr A
lsr A
rts
Notes: BNE is byte-relative, LSR A is a single byte. The nice thing
about this is that it does not require any registers other than the
accumulator (now *there's* an outdated concept - do any really modern
processors have accumulators?), unlike the more conventional method of
using a lookup table, which requires the use of an index (X or Y)
register on a 6502.
Don Stokes ZL2TNM / / vuwcomp!windy!gpwd!don
Systems Programmer /GP/ Government Printing Office PSI%0530147000028::DON
__________________/ /__Wellington, New Zealand_________don@gp.govt.nz________
It's not a bug, its an undocumented feature.
Technical Details
Message-ID:
<466@gp.govt.nz>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!psuvax1!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!munnari.oz.au!comp.vuw.ac.nz!windy!gpwd!gpwrdcsReferences:
<1080@mipos3.intel.com> <4415@bd.sei.cmu.edu> <33334@ames.arc.nasa.gov> <15000@bloom-beacon.MIT.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!psuvax1!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!munnari.oz.au!comp.vuw.ac.nz!windy!gpwd!gpwrdcs From: don@gp.govt.nz (Don Stokes, GPO) Newsgroups: comp.arch Subject: Re: Self-modifying codeREAD/NEW/FOLLOWUP Message-ID: <466@gp.govt.nz> Date: 15 Oct 89 00:00:59 GMT References: <1080@mipos3.intel.com> <4415@bd.sei.cmu.edu> <33334@ames.arc.nasa.gov> <15000@bloom-beacon.MIT.EDU> Organization: Government Printing Office, Wellington, New Zealand Lines: 37