* -------------------------------------------------------------------------------------------- *
| ChaoZers 98/04/23 |
| Assembler Tutorial #01 |
| -------------------------------------------------------------------------------------------- | |
| Bits, Bytes, Words, Longwords & The Binary&Hexadecimal systems |
*----------------------------------------------------------------------------------------------*
Introduction
------------
This is an assembler tutorial for amiga 68K computers, I am going to try to make it as "easy"
as possible...
This assembler tutorial will be for you guys/girls who really want to learn but dont get
a thing from thoose old tutorials that already are available.
I will start the tutorial from the bottom, and then i really mean it!
Though, i really recommend that you have programmed in some language before, like
Basic, C++ or maybe Pascal? If you havent, i strongly suggest you do, because learning
assembly as the first language will be hard for most people i think.
There is an excercise at the bottom of the text, so you can check if you know the things
you have learned :)..
The Binary System
-----------------
This is the computers "decimal system", its not like the decimal system that
we use, let me show you an example of the difference.
The DECIMAL System can use the values 0-9. Example. 64
The BINARY System can use the values 0-1. Example. 01000000
Theese two above values are the same. 01000000 in the binary system is the
same as 64 in the decimal system!
In the binary system a 0 means OFF and a 1 means ON. Get it?
If not, here is what i mean.
%00000010=#2
The binary value here is 2.
If we switch the 1 OFF and change it into a 0 the binary value will be 0 to.
Here is another example.
%00000110=#6
The binary value is now 6, because the digit that stands for a 4 is now ON. 2+4=6.
Argh! Isnt this a bit hard to get used to!? You scream?:)
It isnt. Here is an example again.
$00001000=#8
Do you see a pattern by now?
If not i can tell you that the first digit to the right in the binary system stands for a 1 in
the decimal system. Here is a more clear description.
% 0 0 0 0 0 0 0 0 Binary system.
# 128 64 32 16 8 4 2 1 Decimal system.
So if there were for example 10 digits in the binary value the digit to the left would stand for
#512 in the decimal system. Lets make a bigger table this time, with more values.
% 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
In the above table we have 16 digits(0-15). As you can see the value always keeps doubling itself.
With all theese values you can get almost any value you want, try for yourself.
For the ones knowing a bit math i can tell that the values in a binary systems are powers of 2.
So if you want to know what value the 13th digit in a binary system stands for you just caclulate it!
Its done like this. 2^13=8192
Easy, eh?:)
Can you see the % and # signs?
These tell the assembler what type of system it is.
So the # stands for the decimal system, and the % stands for the binary system.
So if you write #01001000 you will get the decimal value 1001000.
Hexadecimal System
------------------
Ok. Now i hope you know the binary system, beacuse next up is the hexadecimal system!
The hexadecimal system is a bit easier to understand i think.
Lets start with an example.
The DECIMAL System can use the values 0-9. Example. 64
The HEXADECIMAL System can use the values 0-F Example. FF
Strange?? Here is a table on what i mean.
# 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01
$ 0F 0E 0D 0C 0B 0A 09 08 07 06 05 04 03 02 01
But what happens if you have a value as for example the decimal value 23?
Heres another table to show you just that...
# 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09
$ 17 16 15 14 13 12 11 10 0F 0E 0D 0C 0B 0A 09
As you probably figured out the sign $ stands for the hexadecimal system in the assembler.
Here are some examples of hexadecimal values!
$FF=#255 $0FFE=#4094 $FFEE=#65518
Dont be concerned about the "hardness" of transforming between theese two systems, because
moste modern assemblers have built in calculators for this kind of thing.
There you have it its as simple as that!
Bits&Words&Longwords&Bytes
--------------------------
Bits are the values used in the binary system. Yes, the 0s and 1s.
So a BIT can be either 1 or 0, and togehter they can form diffrent values, as seen in the
section about the binary system.
So what the hell is a BYTE?
Well, a byte consists of 8 bits. so for example %01111001 is a Byte, as it
consists of 8 bits.
A BYTE has the maximum value of 255, this is when all the digits are ON. (%11111111)
Lets go on and ask ourselves what a WORD is!?
A word consists of 16bits. so for example %0101101011100001 is a word.
A WORD has the maximum value of 65536.
A LONGWORD consists of 32bits. So for example %1110001010111110100010101011111 is a longword.
A longword has the maximum value of 2147483647.
But what are theese things??
Well, the word&longword&bytes are the things the computer calculates with, so you have probably already
figured out that longwords are slower than words, and that bytes are the fastest to use.
Exercises
---------
*Theese ones are a bit harder than the other.
01.What is the decimal value of %10010000 ?
02.What is the decimal value of %00000111 ?
03.What is the decimal value of %11000001 ?
*04.What is the decimal value of %0000001100000001 ?
05.What is the decimal value of $ff ?
06.What is the decimal value of $40 ?
07.What is the decimal value of $93 ?
08.What is the binary value of #12 ?
*09.What is the hexadecimal value of %00100101 ?
10.How many bits does a longword have ?
*11.How many bytes does a longword have ?
Answers to Exercises
---------------------
01.#144 (128+16)
02.#7 (1+2+4)
03.#193 (128+64+1)
04.#769 (256+512+1)
05.#255 (16*15+15)
06.#64 (16*4)
07.#147 (16*9+3)
08.%00001100 (8+4)
09.$25 (First get the decimal value and then transform it to hex.)
10.32 Bits
11.4 Bytes
Email&More
----------
Want to get in touch with me?
My email is "chaozer@algonet.se".
My homepage is at "http://www.algonet.se/~chaozer/"
You can also find me on IRC, almost everywhere, under the nickname ChaoZer.