The best way to learn about low-level programming is to do it! (At least an emulated version of it using a tool such as the fantastic Little Man Computer simulator available here.)
The LMC instruction set is simpler to the one used in the Cambridge A Level Computer Science 9608 syllabus, but it is similar enough to make a great first step, and you also have the benefit of the animation and visualisation tools from the simulator.
So start with the LMC instructions, which look like this:
An example program, say for adding two numbers, looks like this:
INP
STA X
INP
ADD X
OUT
HLT
X DAT
This article is not about learning LMC per se – I have covered that in other articles. If the above code looks daunting, try running it in the LMC simulator and see if you can follow what is happening. If it’s too difficult to understand at this stage, come back when you’ve studied the basics of LMC a bit more.
The above code in the Cambridge 9608 instruction set (see image below) looks like this:
IN
STO X
IN
ADD X
OUT
HLT
X DAT
Make teaching or learning LMC a cinch with this complete and lovingly compiled(!) Little Man Computer Programming Teaching Pack for Computer Science GCSE and A Level.
[product id=”2838″]
As you can see, the only differences are trivial variations in spelling.
The difference is more significant in the next example. This LMC program accepts input until 0 is entered:
START INP
BRZ END
OUT
BRA START
END HLT
The Cambridge 9608 version uses an alternative system for branching. We have JMP
instead of BZA
for unconditional jumping, but then we have JPE
and JPN
for jumping based on the result of a previous CMP
(comparison). To see this in action, look at the code below.
START INP
CMP ZERO
JPE STOP
OUT
BRA START
STOP HLT
ZERO DAT 0
Converting between LMC instructions and the Cambridge 9608 instructions is fairly straightforward once you are confident with the more basic LMC version. It may seem like extra work to learn two variations but the benefits certainly make it worth it – firstly you can use the LMC simulator as mentioned, and secondly by studying the differences and similarities you will deepen your understanding of the whole topic.
Please note that this is one of the topics in Computer Science which require some deep learning. You should expect to spend a bit of time getting to grips with it and to experience some initial confusion which will give way to various “aha” moments.
Oh, and one little detail that might help: you can’t use END
as a label in Cambridge 9608 assembly as it is a keyword!
Good luck!