🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #2548

Re: Self-modifying code

#2548
From: Michael A. Pasek
Date: Thu, 12 Oct 1989 17:49
32 lines
2170 bytes
In article <9175@etana.tut.fi> pl@etana.tut.fi (Lehtinen Pertti) writes:
>	I've been lately wondering if there is any architecture
>	with possibility to execute instruction indirectly.
>[stuff deleted]
>	I mean something like:
>		exec r0	; execute instructio in register r0

Something like this is certainly possible.  The IBM 360/370 architecture has
an "Execute" instruction.  The instruction allows you to execute a single
instruction "indirectly", with bits 8-15 of the executed instruction modified
by bits 24-31 of a register specified on the Execute instruction.  For example,
to do an immediate compare of a byte value:
         LA     R1,BYTEVAL         GET THE VALUE WE'RE LOOKING FOR
         EX     R1,COMPARE         CHECK TO SEE IF IT'S THERE
             .
             .
COMPARE  CLI    TESTVAL,0          COMPARE

In the above example, the "virgin" instruction in memory has the following
format (assuming that "TESTVAL" is at absolute location 00000123 in memory):
       95000123
It is actually executed (assuming BYTEVAL = X'AF') as:
       95AF0123

The Execute instruction can be very handy for variable-length block moves,
and is certainly much safer than self-modifying code.  Of course, you could
still call it self-modifying, it's just modified in the CPU rather than in
memory :-).

M. A. Pasek          Switching Software Development         NCR Comten, Inc.
(612) 638-7668              CNG Development               2700 N. Snelling Ave.
pasek@c10sd3.StPaul.NCR.COM                               Roseville, MN  55113
Technical Details
Message-ID: <1623@ncrcce.StPaul.NCR.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!ncrlnk!ncrcce!pasek
References: <6481@pt.cs.cmu.edu> <9175@etana.tut.fi>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!ncrlnk!ncrcce!pasek
From: pasek@ncrcce.StPaul.NCR.COM (Michael A. Pasek)
Newsgroups: comp.arch
Subject: Re: Self-modifying code
Summary: Indirect instruction execution possible
Keywords: EX, execute
Message-ID: <1623@ncrcce.StPaul.NCR.COM>
Date: 12 Oct 89 17:49:13 GMT
References: <6481@pt.cs.cmu.edu> <9175@etana.tut.fi>
Reply-To: pasek@c10sd3.StPaul.NCR.COM (M. A. Pasek)
Followup-To: comp.arch
Distribution: na
Organization: NCR Comten, Inc.
Lines: 32