Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Self-Modifying code
Author | Message | ||||
marcwolf Senior Member Joined: 08/06/2009 Location: AustraliaPosts: 119 |
Hi Folks. When we get Peek,Poke, and VarPtr commands like the old TRS-80 you can do some really amazing things. This is something I did back in the 80's Maximite Basic is tokenised which means each command is stored as a byte to save space in the memory. Knowing this it should be possible to work out what token = what command (or download the source and look in there). So. Lets take this program 10 ' start 30-50 your logic code 100 a$=" " 110 b$=" " Now Varptr is the command that returns the location in memory that stores a string. And by using VarPtr(a$) it will give the location of the first byte of a$. Step back 3 bytes in memory and you are positioned at the 'a' in a$. And start to poke in your new tokens using the code in line 30 to 50. When the code execution reaches line 100 there is no longer a string definition but new code ready to run. I used this technique to make a psuedo natural language processor and an advance search engine that generated optimised queries for itself. Not bad in the 80's on a TRS-80 model 3. Hope this gets some folks thinking on the possibilites. Dave Coding Coding Coding.. Keep those keyboards coding.. RAW CODE!!!!! |
||||
Olimex Senior Member Joined: 02/10/2011 Location: BulgariaPosts: 226 |
I do not see what you can make with self modifying code and not with normal code, exept that this makes the code extremly un-readable and confusing for someone with no experience. I would not recommend anyone to use this practice :-) although it looks cool at first sight and shows the interpreter in-deep knowledge. What happens to this code if at one point firmware changes and tokens are different? |
||||
Gadget Regular Member Joined: 22/06/2011 Location: AustraliaPosts: 70 |
I remember self modifying code, was a way to give those classic machines the appearance of some kind of intelligence |
||||
marcwolf Senior Member Joined: 08/06/2009 Location: AustraliaPosts: 119 |
Hi. I certainly would not recommend this for beginners at all, however in the days before compilers this was a reasonable acceptable way to get a lot more out of small machines and even smaller memory. Some people have a fear of pointers, or recursion. But both are also ways to get around the problem. I'm not sure why Geoff would want to change the tokens, maybe add some new but change them. No need for making its something to be scared off Dave Coding Coding Coding.. Keep those keyboards coding.. RAW CODE!!!!! |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1425 |
A little bit different than POKE for self-modifying code would be a MERGE with a starting line number. MERGE "LCD3.BAS", 1000 Not that I see this as common, but you could load a different "driver" code that the base code tests for. If you had a bunch of boards that could have slightly differing hardware, the code could load part of itself with a "MERGE "file", 1000 to match the hardware. This updated MERGE capability (renumbering the BASIC code as it loads) would also be a convenient way to implement loading modular code during development. Micromites and Maximites! - Beginning Maximite |
||||
Print this page |