I read about how LC-3 works, but I can't for the life of me figure out how to code in LC-3 assembly. My goal is to be able to write simple programs like generating Fibonacci numbers or sorting an array.
Can someone point to me to resources to learn this? I'm fluent in Python and Java, so the underlying logic behind those problems is clear to me.
There are several aspects to learning assembly language, which is the human readable version of the machine code of the processor.
Basically other languages are at a logical level, whereas machine code is very much at a physical level
For one, this goes particularly to the difference in the notions of storage:
So, when we write assembly language, we translate our pseudo code: logical code with lots of typed variables of limited lifetime, in part by mapping logical variables onto the fixed physical resources. There are often more variables than CPU registers, especially when some of the registers have dedicated purpose, like stack or return address.
For another, today's other languages generally employ structured programming, whereas in assembly language/machine code we have if-goto-label.
All structured statements have translation in if-goto-label. Each translation is a transformation of a pattern in structured form to a pattern in if-goto-label form. Follow the patterns properly and you'll reproduce the control flow of your pseudo code — very easy to take short cuts here and make confusing mistakes, so I encourage a methodical approach here.
Other languages have rich expressions: having operators of many levels of precedence, and as complex as you like using ()
's. Machine code has instructions that take (usually) at most 3 operands.
Function calls, stack frames, parameter passing, return values are a fairly deep subject, function prologue & epilogue.
For more information, see some of following resources: