ScuzzBlog: Diaries June 2021

Entry 10th June 2021: Post 1: Machine Code - Skimming the light fantastic.

Machine Code - Skimming the light fantastic.

One of the images I showed yesterday was of a small booklet about
Machine Code. I was going to elaborate then but chose not to. In
my early period with the ZX81 I was only too aware of the strict
limitations of the computer in its ability to perform tasks. The
ZX81 was strapped for memory and this constricted its efficiency.
The same was to be said for each later Sinclair computer and you
were soon 'skimming the light fantastic' and dipping into the
bottomless depths of machine code.

From my very earliest editions of my computer rag I was being
coaxed into machine code as a way of speeding matters up. I read
so much about this to the point of sending my brain into a tail
spin trying to understand the CPU registers and how to assemble
and access the computers brain. The challenge was quite an
intoxicating process and one that was limited to my Spectrum era

The point of this comment is that one of the reasons I turned away
from the +2 was the thought of spending every waking hour trying
yet again to get more out of the computer. The Spectrum was a very
good tool, but was nothing without the work and effort needed by
the user to create the magic. What I guess I really needed at
that time was a little easier passage and a more ready based system
that just did stuff without me having to first program the machine.
Times were a changing and reflecting on it today few would even
tolerate the old ways of programming if we had to start over for
some reason.

So when using your phone and tablet and surfing the web imagine
yourself skimming across the ocean of the web and never once taking
the time to peer down into the water. If you were to dive into the
depths of what was below you would discover a bottomless ocean of
magical numbers that when assembled give meaning to your world.
There was a time when we had to compose that language to get any
semblance of reasoned activity out of our computers. It has all
but vanished today and so you are free to click away at your
hearts desire without ever being troubled by such things.

For me I was glad to be shot of machine code as such. I have never
tired of BASIC and DOS based instructions. The world of the CPU
and direct access is still a fascinating subject and one that is
accessible by all. Today's culture however does never want to be
burdened with challenging activities that require a good deal of
time before reaping the rewards. Therefore programming is an
acquired taste. It is what computers were designed for. And so
the art of computing is banished to hushed dark corners of the
world where bedroom programmers are up to questionable activities.
Certainly frowned upon by the mega companies that run the world.
That is why access to the software was constricted by some. Time
was when it was essential to hack the machine to get anything out
of it. Today you would be shot at dawn for contemplating such a

Anyhoo... Here is an idiots guide to the basics of machine code.
I had to do some serious 'skooling' myself before I wrote this.
Took me back to my days riding on the bus into Birmingham and
reading my latest edition of Popular Computing.

Happy days.

Normally the Spectrum ROM will read BASIC lines of instruction and
determine whether they are legal and either store them in memory
or execute them depending on whether the instruction has a line
number. This process is handled by the BASIC interpreter as we are
not technically interacting direct with the CPU of the computer.

The central processor of the Spectrum is the Z80. There are other
chips on the computer but all of these are under direct control of
the main CPU. So when we are talking about programming in machine
code on the Spectrum we are talking about programming the Z80 CPU.

Whilst BASIC is reasonably fast there are advantages to accessing
the CPU direct. This gives faster turn around, less memory and
permits actions not available otherwise. It also frees the computer
from the limitations of BASIC.

Although the black silicon chip Z80 has 40 legs on it only 8 of
those 'PINS' are of use to the machine code language. Note that the
computer responds to electrical signals through these PINS with
the simple yes/no or on/off reaction to a signal being translated
as simple 0 or 1, and so a combination of 8 signals may be shown
as say 00110010. The combination of signals causes the CPU to
perform in a certain way initiating a specific response.

This set of signals become the machine language instruction. And
so machine language in a nutshell is the set of combinations of
signals sent to the CPU that have direct access to the CPU. The
BASIC interpreter simply converts BASIC commands into machine
language so the CPU can initiate the instructions. Some of these
instructions form the core elements that control the way the
computer functions. These core instructions are the basis of the
computer Operating System or as we know it OS.

This middle man of the BASIC interpreter is what slows down the
processes of the computer.

Machine Language or Code doesn't come without disadvantages. The
first is that it is difficult to read and find errors. It is also
difficult to translate to differing computers. It also can struggle
with complex arithmetic such as trigonometry.

OK trying not getting too deep at this stage but the next thing to
understand is Assembly Language. To write in binary or eight numbers
of instruction would take a long time to produce. Better is to
convert to a decimal equivalent and or a Mnemonic [ probably the
bestest word in the English language ]. Therefore a Binary signature
or series of signals long hand would be 01110110. Then in Decimal 
would be 118. And then as the MNEMONIC represented by HALT. [ Sexy
or what ]. This process tells the CPU to stop or HALT.

Irrespective of the interpretation the instruction still has to be
converted to the simple 0 and 1 sets of the initial signal set.
There are two ways to convert the MNEMONIC into numbers. The first
is to use a table of Instructions and Op Codes and simply look up
the respective number. This is called Hand Assembly. To avoid the
possible human error there are programs created or ASSEMBLER so
that the computer can ASSEMBLE a machine code program. In the
end why do anything manually when you have a way more efficient
and quicker computer to do the job.

For all its apparent complexity the computer CPU can only carry out
simple tasks dealing in whole numbers or integers. The simple
way to understand this is to visualise the computer undertaking
simple maths using fingers like a child would. The process or
result uses simple memory boxes to store the consequential process.
This analogy of fingers can be extended to allow the computer to
count on its toes. The limitation is set by the numbers of fingers
and toes the CPU has... Remember that only whole numbers can be
stored. The size of the numbers is set by the amount of fingers
the CPU has albeit this limitation can be appeased by the CPU
using also its toes to count with [ Bonkers ].

This is where it gets crazy... cus the computer unlike us has
several hands and eight fingers on each. Further the feet have
sixteen toes. The CPU is also able to count up to 255 on each of
its hands and up to 65535 on each of its feet.....

All that said just imagine the CPU Z80 Register Set as 8 hands or
8 boxes set in pairs on top of each other labelled with the letters
A through to L. Below are two further boxes or feet sitting one on
top of the other labelled IX and IY.

A    F
B    C
D    E
H    L

Interestingly all hands can be used for counting with the exception
of the 'F' hand which has a special purpose determining if a special
event has happened. Kinda a long way round to explain CPU Registers.

That really is as far as I am prepared to discuss. I suggest if
you are interested you get a good book on Machine Code. Then you
can go swim with the fishes.

Machine Code - Skimming the light fantastic.

scuzz site

If you can only see this CONTENT window
then click the image above for the full site

Last updated 10th June 2021

Chandraise Kingdom

Keep the Faith
scuzzscink 2021