PASM Self Modifiying Code via Label Modification ?? Really??
greybeard
Posts: 65
I recently ran across a set of PASM code I do not understand. I have re-constructed a fragment here. The code works but I don't understand why!
I can tell that the author is working with 3 arrays that consist of next, lows, and highs each separated by the size of the arrays. What APPARENTLY happens is that the variables next1, low1, high1 is initialized first, then next2, low2, high2 ...etc . Is the code actually manipulating the local labels of the code. What is the PASM doing??
MOV X, SIZE
:P1 TJZ enabled, #label ' if not eneabled, skip --- THIS I UNDERSAND
:P2 MOV T1l, cnt ' set start time ---
:P3 ADD T1l, next1 ' set next time
:P4 MOV T1h, low1 ' get low time
:P5 ADD T1h, high3 ' set high time
ADD :P1, C1 ' move dest --- ?????
ADD :P2, C1 ' move dest
ADD :P3, C2 ' move dest and source
ADD :P4, C2 ' move dest and sourc
ADD :P5, C2
. DJNZ X, #:P1 ' go to next set
label
.
.
C1 Long 1<< array_size
C2 Long 1<< array_size +1
next1 long 0
.
.
low1 long 0
..
..
high1 long 0
.
.
T1l res 0
T1h res 0
I can tell that the author is working with 3 arrays that consist of next, lows, and highs each separated by the size of the arrays. What APPARENTLY happens is that the variables next1, low1, high1 is initialized first, then next2, low2, high2 ...etc . Is the code actually manipulating the local labels of the code. What is the PASM doing??
MOV X, SIZE
:P1 TJZ enabled, #label ' if not eneabled, skip --- THIS I UNDERSAND
:P2 MOV T1l, cnt ' set start time ---
:P3 ADD T1l, next1 ' set next time
:P4 MOV T1h, low1 ' get low time
:P5 ADD T1h, high3 ' set high time
ADD :P1, C1 ' move dest --- ?????
ADD :P2, C1 ' move dest
ADD :P3, C2 ' move dest and source
ADD :P4, C2 ' move dest and sourc
ADD :P5, C2
. DJNZ X, #:P1 ' go to next set
label
.
.
C1 Long 1<< array_size
C2 Long 1<< array_size +1
next1 long 0
.
.
low1 long 0
..
..
high1 long 0
.
.
T1l res 0
T1h res 0
Comments
e.g. by adding 1 to the move instruction, the destination field will be incremented by 1
There's also a link to Phil's tutorial on how to post code to the forum in post #3.