View previous topic :: View next topic
|
Author |
Message |
anonguy456
New User
Joined: 29 Jun 2021 Posts: 16 Location: India
|
|
|
|
i am not able to understand what exactly line 2 is trying to do in the below attached code. normally MVI instruction is used on a variable, but here it is getting used on a para name. even though line 2-4 are getting executed sometimes, looking at the below code it feels line 2-4 will never get executed.
Code: |
PARA1 B PARA2
MVI PARA1+1,X'F0'
MVC VAR1+64(25),MSG01
BAL R14,CHECKAGE
PARA2 ZAP DEBIT,=P'0'
|
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
As posted, lines 2 through 4 will never be executed.
HOWEVER, that MVI instruction is changing a byte in the code stream which means what you are seeing is not necessarily what is being executed. Dynamically changing instructions while a program is executing can be done (COBOL, for example, used to have the ALTER GO TO construct to do this) -- but it is ALWAYS dangerous and a very bad practice to do. Debugging such a program can be pretty close to impossible without lots of dumps and careful inspection of memory to see what the code changes have done. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2144 Location: USA
|
|
|
|
Yes, I agree: any self-modifying program is a dangerous and bad practice of coding.
In my opinion, any developer who has ever created a self-modifying code, deserves nothing else but death penalty. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2144 Location: USA
|
|
|
|
anonguy456 wrote: |
i am not able to understand what exactly line 2 is trying to do in the below attached code. normally MVI instruction is used on a variable, but here it is getting used on a para name. even though line 2-4 are getting executed sometimes, looking at the below code it feels line 2-4 will never get executed.
Code: |
PARA1 B PARA2
MVI PARA1+1,X'F0'
MVC VAR1+64(25),MSG01
BAL R14,CHECKAGE
PARA2 ZAP DEBIT,=P'0'
|
|
Most likely, the whole code also includes another instruction like
The original instruction
PARA1 B PARA2
is assembled into the code
X’47F0bddd’
Where bddd is base and displacement of PARA2 label.
After MVI PARA1+1,X’00’
the instruction code is changed to
X’4700bddd’
which in turn works as if it was the Assembler instruction
PARA1 NOP PARA2
So next time the point PARA1 is somehow reached, no branch is done, but the instructions below PARA1 are executed normally. The first of those MVI reverts the updated PARA1 instruction back to
PARA1 B PARA2
and this group of instruction should not execute again unless any MVI …,X’00’ changed the B instruction to NOP.
Please, never try to repeat this exercise again! |
|
Back to top |
|
|
anonguy456
New User
Joined: 29 Jun 2021 Posts: 16 Location: India
|
|
|
|
Thank You Sergeyken. |
|
Back to top |
|
|
|