Copy Link
Add to Bookmark
Report

Saxonia Issue 01 Part 009

eZine's profile picture
Published in 
Saxonia
 · 5 years ago

  

Assembly course part 1.
By Rumrunner/VOID
~~~~~~~~~~~~~~~~~~~~~~~

Right on, if you want to learn to code, the first thing you need to
know is what the different instructions do, and how to use them.
I think the best way to start off, is with an example. Look here :


section everything,code_c

testmouse:
btst #6,$bfe001
bne.s testmouse
rts


Type this into your assembler, assemble and run it. I assume that you
have figured out how your assembler works, but to make it short, in
asm-one, use a (return) to assemble and then j (return) to run. Use
control-a to assemble and control-x to run in Devpac.

When you run the above example, you will se that the assembler will not
receive anything (try writing something in asm-one).
When you press left mousekey, you will get back to the assembler, and
you can type again.

Right then, let's explain the example line by line.

section everything,code_c :

This line tells the assembler that whatever comes under should be
placed in chipram (hence the _c) and that it is a code hunk. Hunks are
a nice feature in the Amiga that let's you have code, data and more code
(and so on) all chucked in one file, and it can still load in different
places in memory. The "everything" is just a name for the hunk, it can
be whatever you like.


testmouse:

This is a label. You can use almost everything you want to as labels,
with the exeptions of some reserved words. You use labels for referring
to memory, such as where you want to jump to, where you want to get
data from, and where you want to write to.

btst #6,$bfe001 :

Here, we check bit number 6 in adress $bfe001.
Let's look at the byte in $bfe001 :

%0 0 0 0 0 0 0 0 <-- This is the byte written in binary
| each zero represents a bit.
|
|
We want to check this one.

Performing this operations sets the status register (SR), which is
neccesary for the next operation:


bne.s testmouse :

Bne.s means branch (a jump) and the .s means that it is a short jump to
be performed. You want to branch to the memory position that you have
labelled testmouse. But that's not all. Bne is not just a branch,
it only branches to testmouse if the status register has the correct
bit set. Remember that the previous operation has set this register for
us. So, the program will run between testmouse: and the bne.s ...
until you press the left mouse button. Then the flag required for a
bne jump will not be set in the status register, and the program will
continue to :

rts :

This is a simple one. Return from subroutine will either continue
program execution from the place you hae done a branch subroutine
or jump subroutine to, or, if you have not used bsr or jsr, it will
end the program.


Right, think about that for now, and I'll come up with something a
little more advanced for next time.


← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT