public

Learning Assembler on Amiga #6 - Addressing

By users' requests, I built an index page of previous lessons. It’s here [https://www.iamsensoria.com/2018/09/amiga-learning-assembler-step-by-step/]. As promised in lesson five [http://iamsensoria.com/post/

5 years ago

Latest Post The Great Escape Tunnel by Mario Esposito public

By users' requests, I built an index page of previous lessons. It’s here.

As promised in lesson five, we would have addressed, all puns intended for that lesson, a way of storing and pointing to data in memory.

Memory

Memory in a system is divided like a group of homes in a condominium. One next to the other and each one has its own address. Of the wonderful Amiga condominium from $000000 to $800000 you meet the first 512k for the CHIP ram type. From $c00000 to $c800000 you meet 512k of FAST ram. There are multiple hardware chips in the Amiga systems, I am sure you heard of PAULA, DENISE, and so on.

The landlord of all memories is called Guru Meditation and when you piss it off it, shows its anger like this

Kernel crash

Each code reported has its own meaning and at some point, they will really mean something to you when hunting for "what's going here" moments aka crashes. Those are those special fragments of life where your nuts just spin around while you figure shit out. You have to accept it for what it is...

Size matter

Information in the form of byte, word, or long-word can be stored and located using addressing. I made the table below to help you to understand how it works as a refresh of what was explained in lesson 5.

Every line of your code will be translated into machine code which is even a level deeper than writing this

move.w $something1, $something2

as an example the instruction move has its own hexadecimal representation in memory because the hardware doesn't understand English... They are called OpCodes and are mapped to electrical impulses that translate for the Motorola what you are asking it to do. Picture you signaling with a flashlight, to somebody across the street that your wife is asleep and you can't play Silk Worm tonight. ON-OFF-ON-OFF let's try tomorrow at your house... I digress...

The actual flashlight is the move command and the on/off sequence and length between signals is the operands

Opcodes are the numeric codes that hold the instructions given to the computer. (move in this example). Right after the instruction, you find the size the operand should work with. In the example above .w – those have their own representation as well.

Motorola has its own opcode list and although at first seems like a shot in the head by a laser cannon would be less painful than going through PDF, if you focus your attention on one Opcode only (move) the rest will fall into its place without effort. Let's take one example that clicked for me.

move.w    #$4000, $DFF09A

If you compile that instruction and look at its memory you will notice that it is represented as

33 FC - 40 00 - 00 DF F0 9A

For a while, I kept wondering "I know from where 40 00  and DF F0 9a are coming from, but what about that 33 FC and the 00??

As it turned out the first two bytes is the opcode, followed by its two operands. The operands are not of the same size. One is two bytes and the other is four bytes. Let’s take a closer look at the opcode.

Thank you Mark!

If you haven't friend that only neuron that was wandering in your skull with all the above just think about it then back then not understanding all this shit was not just because you loved video games more than code, it was because it's freaking hard!

Gibberish: $ then # and even %

An offset is a directive that means “addressing”. Just like in a battleship game where using row and column you identify a spot on a grid. An offset lets you pinpoint a place in memory. I made a grid below to help you to grasp the concept. An offset is made of 8 digits, I added the spaces for readability, normally you won’t find any.

The column 0-F is expressed in hexadecimal and therefore they go from zero to F. I made a few examples below for all data types that we have explored so far.

one byte (8 bits), one word (2 bytes), long word (four bytes)

The dollar sign indicates that the value (after the sign) must be interpreted as a hexadecimal value. The assembler will translate that value into binary. If for some reason you want to avoid any transliteration from hexadecimal to binary, then you can use the % sign followed by the binary value. When you want to operate between addresses in order to differentiate a value from an address you use the dollar sign.

Instead, if you want to pass an exact value you want to add the pound sign (#) ahead of the notation. Like #$10A10B. It behaves like a constant value passed on.

An example will make it even more obvious.

To copy a value from memory location 00000010 to 0000002D address, you use the following notation:

move.b    $10,$2D

instead, if you want to write an exact value into an address (e.g. 0000001E), you use:

move.b    #32,$1E

The .b at the end of the move directive above stands for byte. Naturally, you would use .w (word) or .l  (longword) if the values, part of the operation were bigger in size. These four methods aren’t the only ones available to the MC68000 processor, in fact, there are a total of 12 ways; which are in a fashion or the other a combo of these three methods.

from MOTOROLA OpCodes

To summarize:

# means direct addressing. You set a value into a data registry. Example: move #1,D0. This can be used only as of the source of an operation, not the destination. Basically right after the move instruction, not after the comma.

$ means the value after me is a memory address. Example: move $00000010,$0000002D

We are done for today. Practice makes better, enjoy your newly acquired knowledge and keep retroing.

#A99

Mario Esposito

Published 5 years ago