IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

self modified code in Assembler


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ganeshptrk

New User


Joined: 04 Apr 2007
Posts: 17
Location: Chennai

PostPosted: Fri Jul 06, 2007 3:52 pm
Reply with quote

Can anyone tell me what is "Self-Modified" code in Assembler. this was one of the interview questions.

Thanks
Ganesh
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Jul 06, 2007 5:27 pm
Reply with quote

Since an assembler program has access to all of its memory, it can change the value of instructions as well as data. While there might be very special reasons for doing so in extreme cases, the executed program at this point will not match the original program, so tracing, debugging, etc., will be seriously compromised.

Anyone got a good example of when this is a good technique?
Back to top
View user's profile Send private message
ganeshptrk

New User


Joined: 04 Apr 2007
Posts: 17
Location: Chennai

PostPosted: Fri Jul 06, 2007 6:20 pm
Reply with quote

Can you give me an example instruction for this please...?

Cheers
Ganesh
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Jul 08, 2007 6:18 am
Reply with quote

Hello,

There is no particular single instruction - the 2 "straight" instructions i've seen the most used to self-modify code is a MVI or an MVC (Move Immediate or Move Character).

Another is building an instruction to EXecute on the fly.

What typically happens is that the programmer creates an instruction on the fly, modifies one or more parameter(s) of an instruction, or forces an ungraceful abend at some point where they wanted an abend. The last case is very seldom used anymore (from what i see these days) - the debugging tools are such that this is not as handy as it once might have been.

Another technique that was used due to limited memory was to "set aside" a bit of memory called transient areas. Code that was not even in the main assembly/link would be brought in at run time as needed. This way the total executable size was reduced and the dozens or hundreds of transient modules were run from the transient areas.

Phil - one place i was, this was often used for a first-time switch. The code was such that the first time thru, the code modified itself to branch the one-time logic.

There was also code that set bits whose content wasn't known at assembly time, so the actual instruction was created and EX'ed at run-time.

With nearly unlimited memory and better programming practices, i'd recommend against self-modifying code as a practice (execpt where it really does make sense).

One of the worst times i ever had was trying to figure out what was going on in a program that modified branches all over the place. When i asked how the code got that way (it did not look like it was designed, but just kinda happened), i was told that the author had the habit of forcing the code to go where he wanted it when there were problems rather than fixing the problems. The author no longer worked there and there were several of his time-bombs that had to be dealt with.
Back to top
View user's profile Send private message
Microchip
Warnings : 1

New User


Joined: 28 Feb 2008
Posts: 2
Location: Citrus Heights, California

PostPosted: Wed Mar 05, 2008 1:57 am
Reply with quote

I can think of only ONE good, and acceptable use of self-modifying code: a first-time thru process.

MAINLINE EQU *
NOP NOT1st Do following only first time thru
MVI *-3,X'F0' Turn on the above NOP
WTO ' Hello, world! I am here!'
Not1st EQU *
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sun Mar 09, 2008 12:04 am
Reply with quote

What Dick has said is very true and I've experienced this in many of the systems which I've maintained.

Manually inserting the length of Operand-1 into the next instruction, such as an MVC, CLC and/or an XC will someday, rear its ugly head, leaving the poor slob who has to fix the problem, scratching their own (been there, done that, got the tee shirt). icon_smile.gif

To reemphasize, an EX should ALWAYS be used to do this and many times when it's not, I find it was either the lifting of previously written bad code, a matter of convenience or just outright laziness on the part of the programmer.

So, DON'T MODIFY INSTRUCTIONS, UNLESS YOU USE APPROVED AND DOCUMENTED METHODS!

OK, I'm done.... icon_wink.gif

Regards,

Bill
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
No new posts VSAM return code 23 - for a Random read COBOL Programming 4
No new posts Monitoring production job progress. N... JCL & VSAM 4
Search our Forums:

Back to Top