top of page
Search

[55] Twenty Thousand Leagues Under the C

  • Writer: Conlan Walker
    Conlan Walker
  • Oct 28, 2022
  • 2 min read

It really isn't much of a hot take to say that any type of assembly language is more difficult than its higher-level abstractions, but it's sometimes necessary if you need exact control of your processor. For me, at least, the most diffucult part is program control, aka control flow.

These are things like "if" statements, "for" loops, et cetera.

With assembly, it's a lot different, and more difficult. In 6502, there's no such thing as an "if" statement, or any sort of formal loop system. What you have is branches, and all they're designed to do is change where you are in code given a certain condition.

ree

In this case, it's in the form of checking certain bits. This tiny spreadsheet here

shows how different bits are affected when comparing numbers in 6502.

You might notice that the "Z" bit is only set when the comparison is equal.



For example, I'll show a small bit of c code, as well as an implementation of it in 6502.

ree

the "A=some_variable" thing is technically redundant, but it's done here for demonstration, so the 6502 has direct parallel.





And here's a 6502 equivalent:

ree

Often it's better, if not required, to skip code if the condition is not met, rather than execute that code if the condition is true. That's also demonstrated above.

I'm still not the best at control flow, but I of course am better than I used to be.

For some practice, I spent a long while making this:

I'll put a screenshot of the code here because I'll be asked about it if I don't:

ree

(Above file is called "amoogtest.s")

Other than that, I'm working on reformatting the project repository, as well as figure some things out regarding the internals of how cc65 and ca65 handle libraries, and managing scope on a file-wide scale.

That's it for this week.

 
 
 

Comments


bottom of page