self-modifying code
rjo_
Posts: 1,825
Hi Guys,
I have tried to read everything about self-modifying code... and I just don't get it.
I have used self-modifying code in higher level languages... So, I grasp the basic concept... but I have read Graham's questions and the responses, and I have done searches from several different directions. It seems like there is somethng missing. I feel so ignorant I don't even know how to ask the right question. The best issue seems to be table indexing in assembly.
Could someone post a complete example that does nothing but index through a dat table and pass the values back to a Spin array... ?
I'll be running around too much to respond for a few days... (a teenage daughter[noparse]:)[/noparse]
Rich
I have tried to read everything about self-modifying code... and I just don't get it.
I have used self-modifying code in higher level languages... So, I grasp the basic concept... but I have read Graham's questions and the responses, and I have done searches from several different directions. It seems like there is somethng missing. I feel so ignorant I don't even know how to ask the right question. The best issue seems to be table indexing in assembly.
Could someone post a complete example that does nothing but index through a dat table and pass the values back to a Spin array... ?
I'll be running around too much to respond for a few days... (a teenage daughter[noparse]:)[/noparse]
Rich
Comments
If you want to take a look at some self modifying code in a real application, take a look at the code for the logic analyser I wrote: http://forums.parallax.com/showthread.php?p=606048
If you scroll down to the the assembly code, GetFast's storeloop is about as straightforward as it goes for a real world example. It·also shows you can modify code without using the movd or movs instructions.·The constant d_inc is the value 1<<9 or the least significant bit of the destination register, so by adding this value to the previous mov instruction, each successive mov is writing the contents of ina to the next location in memory.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Thanks. My search skills seem to be deficient as well[noparse]:)[/noparse]
Rich
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Andy
If the forum was periodically offered on a $CD... I· could have found your post on my Mac[noparse]:)[/noparse]!!!
Andy,
Exactly!!!· I am in the Blue Grass State, without my Prop.· Won't be home til Sunday... try it then,
Thanks.
Rich
Your example was perfect... and as usual, you gave me something to think about...
BTW... you have gauged me correctly... if you hadn't explained the d_inc... (1<<9 ) ... I would have thought you were joking[noparse]:)[/noparse]
Rich
I realise this is a long dead thread, and there are probably numerous others referring to the same thing, but I am having serious difficulty with self modifying code. I have looked for keywords on the forums and google (movd, self modifying, etc) for the answers, but all the code examples seem to be similar, and no one seems to have had the troubles I see.
I'm attempting to write an audio tuning application for the demoboard using an audio sampler, a number of FFTs, VGA and serial. Trying to pass hub ram FFT input array pointers to the sampler cog.
The following example, taken from various forum posts and web pages, attempts to add 1 into the destination field of the rdlong instruction, labelled :patch.
d0 being a long defined as 1 << 9, and param_count declared as a CONstant
I understand the need to have an instruction in between the instruction to modify and the modified instruction because of the interleaved fetch execute cycles.
I get some seriously strange behaviour, my serial cog starts flooding me with lots of #, ? and $ symbols, with the occasional sporadic other character in there too...
The screen starts making some seriously funky fast flashing colourful patterns too. Obviously the "add :patch,d0" instruction isn't having the intended effect.
The only way I've found I can get the behaviour I want, within a loop, is to use an intermediate pointer and re-hit :patch with the movd instruction:
Can any propeller gurus tell me what I'm doing wrong? Why won't adding d0 to :patch increment the destination operand in the expected way?
I'm glad I've got it working to some degree, after a day of forehead vs keyboard interaction and epilepsy inducing visions on the screen, but it seems more round-about and less elegant than the method advertised.
Thanks all,
Pete
Page 23 of this PDF is where I got some ideas:
http://www.cp.eng.chula.ac.th/~piak/project/propeller/machinelanguage.pdf
In your app, do you have d0 set as follows?
or to something else that evaluates the same?
Also, just as an FYI, it's become customary for PASM arguments that are the target of self-modifying code to be expressed as 0-0.
-Phil
I modified the version of Beau's fixed point FFT to accept pointers of hub ram instead of constant memory locations. (Out of interest, is there a way of telling the compiler to allocate a 1024 word buffer at a certain hub location, e.g. $5000... It allocates it at compiler time right? So can you tell it you want it to be explicitly in a certain location?)
Got it from here:
http://propeller.wikispaces.com/FFT
I modified the microphone to VGA demo to write to FFT buffers. Since the audio sampler seemed to be about 2 1/2 times quicker than the FFTs (to the best of my ability to tell using serial to print out clock values) I had four running and used the flag pointers to communicate when their buffers were full or finished. Each FFT plots to the screen by XORing pixels, so it seems to work nicely at 19.5 KHz and 38 KHz, but any higher and the sampler starts over writing the input buffer before the FFT completes and it shows on the screen..
In my main object I have declared these:
here's the sampler code in its entirety..
I realise this gets a bit messy without comments, and the last bit of my code could use some work.. Anyone got good methods of switching between 4 different buffers?
-Phil
Cheers for explaining that! Not more tears ^_^