How to use Assembler? part 1: introduction
This article will come in 4 parts and will cover everything you will ever need to know about programming in assembler in Flowstone 3.0.5 and lower (including Synthmaker). This part will cover the introduction to assembler.
How your mom does math and how your computer do it
Everybody who ever used a computer noticed the language and mentality gap between us. And those of us who ever tried making a program noticed how deep and wide the gap actually is. Fortunately many tools are here to help us with the task and Flowstone is one of them. Apart from the easy-to-follow wires and modules, Flowstone allows you to write parts of your schematics the old-fashioned way. Naturally I’m talking about Ruby, DSP code and x86 Assembler, which is the topic today.
To get a glimpse of what assembler is, why it looks like the way it looks and how to use it, we have to start from the number 1 question of 21st century humans, which only a few know the answer too: “How do computers work?”
I will try to make the answer as simple as possible. The “brain” of your computer is made of two parts:
1. RAM (random access memory) – A big array of flip-flop circuits (on/off switches). They are in groups of 8 and each group has its number called address (which is 32bit or 64bit integer that’s why there are 32bit and 64bit systems).
2.CPU (central processing unit) – a nerd-ish brother of a calculator. Instead of pressing buttons it reads the instructions (operational codes or shortly opcodes) from your RAM. Some instructions naturally require some values which he also reads from your RAM or stores them in his own personal short-term memory called registers and flags.
When you compile your code/schematic your operating system stores the instructions in your RAM and also makes place there for your variables. CPU then reads the instructions one by one and performs them. That may involve reading data from RAM, writing data to RAM from registers, jumping to different instructions or doing stuff with the registers and flags. Most of the opcodes do basic “elementary school” level math and assumptions. The power of computer is, that while a student needs several seconds to add two 8digit numbers your computer does in splits of a microsecond.
How do I make a computer do what my mom says?
Making common programs by writing the binary of opcodes (referred to as machine code) is superhuman task. Just try to remember that operation 0000001100001100 adds contents of “ebx” register to “eax” register. Luckily someone give each instruction a name and thus created assembly code and also wrote a program that can convert these names to instruction numbers (the assembler). Both machine code and assembly code are low-level programming languages. High level languages are even more practical – they convert more complex terms like c=a+b to sequence of assembly/machine code instructions, letting you write more complex programs very easily.
Here you can see the transition from what your mom would easily understand to what your computer understands. From top to bottom: word-based thoughts, DSP code (high-level language), x86 assembly (low-level language), machine code (in hexadecimal numbers). Notice how things transform from simple thoughts to math notation to some babble with bliss of structure to utter nonsense. Well… from your computer’s point of view it’s other way around.
Next time we will have a look at some basic programming in Assembler using SSE operations…