Self-modifying code on the SMS

The Master System & GameGear are virtually the same hardware!
Post Reply
Jabberwocky
Posts: 4
Joined: Sun Jan 24, 2021 1:32 am

Self-modifying code on the SMS

Post by Jabberwocky » Fri Mar 05, 2021 4:10 am

Hey! So while I'm still fairly new at this, I vaguely recall something about self-modifying code being not common on the SMS (and presumably other game consoles, but that's just an assumption). What's the reason for that? Is it because computers typically have more RAM than game consoles? Or because you have to use it for your own code filling in for firmware? Sorry if it's a super beginner question, and I'm not through all of the tutorials yet, so feel free to point me to the relevant one (which I'll just wait for and watch in order anyway).

In short, is there some reason, other than RAM limitations, to avoid self-modifying on these systems?

User avatar
akuyou
Posts: 463
Joined: Mon Apr 22, 2019 3:19 am
Contact:

Re: Self-modifying code on the SMS

Post by akuyou » Fri Mar 05, 2021 7:26 am

I think there's probably a couple of reasons

1. As you said, Code can only be modified if it's running from RAM, so code running from ROM cannot be modified.

2. self modifying code is a way of speeding up your program, and saves memory, but it make debugging and troubleshooting harder, If you have a lot of CPU speed, and don't want to lose labour time fixing your code, Self modifying code will be best avoided.

3. I'm not sure how relevant self modifying code is to programs written in C and other high level languages, In ASM you know exactly what commands the CPU will run, but in C there will be a stage of conversion from C to machine code you would have to factor in. I assume it's possible, but it's not something I've come across

It's my understanding that self modifying code (or at least self writing code) was still used on PC's for things like video decompression where speed was paramount around 2000, I know the Data Execution Prevention stopped some of this for security reasons, I'm not sure how relevant it is in modern computing.
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

Jabberwocky
Posts: 4
Joined: Sun Jan 24, 2021 1:32 am

Re: Self-modifying code on the SMS

Post by Jabberwocky » Mon Mar 15, 2021 4:17 am

Ahh alright! So if I'm reading that right, it's not something you should necessarily avoid like the plague, but it's just likely not the best use of the resources available.

As far as C and such, I'm not too worried about that as the only extensive coding I've done was in AutoLISP. Fascinating about modern machines and self-modifying code, though. I'll have to see if I can research anything on that!

Post Reply

Return to “Master System & GameGear Assembly Programming”