What exactly do you mean by "how the stages work"? You mean, which level (1-1, 2-1 etc) you start on?
I gave SMB 1 a quick check and it looks like it doesn't even set a beginning level; it just assumes to be starting at stage 0 and increments it by 1 when you go to the next level. I assume that if you are on stage x-4 it increments the world # by 1 and sets level # back to 0.
In RAM $075A is your current world -1 and $0760 is your current level -1.
I'm only a newbie ASM hacker so hopefully someone can be more help than I am. I didn't check SMB2j because I don't have an FDS emulator with a debugger.
It's probably RLE. Super Mario World 2 worked that way anyways. It was like. 01FF88FE87DD00 resulting in FF FE FE FE FE FE FE FE FE DD DD DD DD DD DD DD or smth along those lines.