Learning Assembler on Amiga #10

By users request, I built an index page of previous lessons. It’s here and as usual, read my disclaimer. Let’s begin…
In this lesson, we’re going to put together everything we learned in Lesson 6, 7, and 8. Buckle up!
No matter what type of language on which type of hardware you want to master your skills, there’s a sanctioned truth that no one can escape. The Debugger!
If you can’t “look into” what your code does while it’s running or after it executed some code then you are flying blind. And that is Russian roulette buddy.
image
There are multiple ways and tools to debug your code. Each way has bugs and inconvenience but in the end, once you develop your own methodology and muscle memory you adapt to anything that floats your boat best.
The most obvious way of debugging is with Asm One, the second most obvious way is to use Visual Studio Code with an extension that leverages in the back vasm and vlink in combo with FS-UAE.  The debugger behind the scene for this “hack” is Capstone.
If you want to test things out directly into an Amiga environment, Asm One is the way to go as you experience and see things as back in the days. If you want the speed of execution (mechanical not digital) then you want to leverage more modern things like Visual Studio Code.
image
I am still learning my way through the Visual Studio Code option and since everyone that shares material around that subject online either assume that the target audience was born in a chip factory or spells like someone that had plenty of vodka before puking some knowledge, I need more time to figure it out on my own.
Therefore, to put at test what we learned in lesson #8, we are going to use Asm One.
Here are the things we have to learn before we start jamming code like maniacs!
SETUP
Make sure that you have installed Asm One as per the version I have with the same settings. 
Asm One,  COMMANDS
Asm One has menus that you can access just like in another Amiga application. However, because you move a lot between the various parts of the developer IDE (debugger, editor, assembler…) it’s a lot more practical to memorize a few short commands that will make you be more focused on the code and debugging and less on “where’s that menu…”. The shortlist for today:
zs = zap source = new file
wn = save file
r = open file
h <address/symbol> memory dump with using the provided starting location in memory
a = assemble my source
j = run my code
Unless you have changed it, don’t worry about case sensitive Unix typical nightmares.
ASSEMBLER COMMANDS
MOVE = see lesson #7
ADD    = Add a value into a location (registry, else)
LEA     = It stands for load effective address. Takes data from a constant and puts into an address you indicate
TST     = Test if an operand is zero
BEQ    = Branch if the result is zero. In lesson #7 you find more details about branching
BRA    = Branch always. Not it’s not an undergarment for women. It’s the equivalent of a GOTO in the old basic.
DC      = It’s a mechanism for storing constants/data into memory, you can give them names and then refer to such data using their mnemonic names.
CODE
Launch FS-UAE (or the actual machine) and launch Asm One. Then let’s start with what we learned in lesson #8, let’s put something arbitrary as 1234 into the D0 registry.
Here is the code:
image
hit the ESC button to go to the command line and enter A to assemble. If you didn’t mess anything up (spaces or other typical issues), you should see this output:
image
If you don’t that output, then the most common issues that I have run into at the beginning were:
  • I didn’t put at least one space on each line of code. Only labels take no space as the first character
  • I added a space after the comma (very rookie mistake, now I understand…)
  • Anything else, well…glasses or better glasses? :-)
To execute the code you just built, just run the command J the output is expected to be like this.
image
Notice that in the D0 registry now you have our magic 1234. Time to celebrate!!! Of stop running amok, we got more code to write, drop that Mojito and let’s go back to the keyboard.
In lesson #6 we learned the importance of offsets and how to shift information from one location to the other.
image
Perhaps the most important aspect of that lesson is that you can put some data into a location (e.g. A0) using this notation: move.b  $000010,$00002D or you can use the indexing feature and add data to the existing targeting address. From lesson #8:
As you can see, a0 acts as a gateway to memory. The address registers support a feature called indexing.
move.b    #$9B,$04(a0)
The $04 you see right before the parenthesis, is the index value, this will add to the offset inside a0 to give you a new offset.  So a0 contains 00000039, you add 04 which gives you 0000003D, so, 9B is moved to offset 0000003D:
to be continued… (dinner is ready and it’s Christmas eve…)
Happy holidays!!!

Comments

Popular posts from this blog

Zen-inification - The art of decluttering

Postgres on Synology

Bring Boxee Box back to life