Merge pull request #16 from SnorreSelmer/SnorreSelmer-patch-1

Update mips-programming-101.md
This commit is contained in:
Snorre Selmer 2024-05-28 21:38:59 +02:00 committed by GitHub
commit bf220fcf14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,7 +10,7 @@ In Stationeers you have the following available to you:
- Sixteen registers (r0 through r15) - Sixteen registers (r0 through r15)
- A special address register (ra) - A special address register (ra)
- A stack (sp) that you can push 512 values into, and pop values out of. The stack is last-in-first-out. - A stack (sp) that you can push 512 values into, and pop values out of. The stack is last-in-first-out.
- A maximum of 128 lines of code, each line has a maximum of 52 characters - A maximum of 128 lines of code, each line has a maximum of 90 characters
The address register (ra) is not meant to be written to by the user, it's only used for branching to code that needs to be accessed from multiple areas in your code (functions). The address register (ra) is not meant to be written to by the user, it's only used for branching to code that needs to be accessed from multiple areas in your code (functions).
@ -134,7 +134,7 @@ j start
> >
> *- Guido Van Rossum (the guy that created the Python programming language)* > *- Guido Van Rossum (the guy that created the Python programming language)*
While the MIPS implementation in Stationeers has some limitations (128 lines, with a maximum of 52 characters per line), I've rarely run into problems like running out of room. This is mostly because I try not to write "multi-mega-scripts" that do a ton of things. I'm a fan of the UNIX mantra of "do one thing, and do it well". This also means that I use ***aliases*** and ***defines*** a lot. They take more space than just writing things straight up, but they also make the code much easier to read! While the MIPS implementation in Stationeers has some limitations (128 lines, with a maximum of 90 characters per line), I've rarely run into problems like running out of room. This is mostly because I try not to write "multi-mega-scripts" that do a ton of things. I'm a fan of the UNIX mantra of "do one thing, and do it well". This also means that I use ***aliases*** and ***defines*** a lot. They take more space than just writing things straight up, but they also make the code much easier to read!
Compare these two lines of code: Compare these two lines of code:
``` ```
@ -145,7 +145,7 @@ and
slt HeaterOn CurrentTemperature MinimumTemperature slt HeaterOn CurrentTemperature MinimumTemperature
``` ```
They could do the exact same thing, but the bottom one actually explains what's going on. And it's still shorter than 52 characters. They could do the exact same thing, but the bottom one actually explains what's going on. And it's still shorter than 90 characters.
If you're juggling 10+ registers in your code without naming them, the chances of getting them mixed up increases greatly. And if you do make a mistake somewhere, trying to follow the code can be more complicated than if you used named variables. If you're juggling 10+ registers in your code without naming them, the chances of getting them mixed up increases greatly. And if you do make a mistake somewhere, trying to follow the code can be more complicated than if you used named variables.