ctpart_1

Upload: amiga68000

Post on 08-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 CTPart_1

    1/4

    * -------------------------------------------------------------------------------------------- *

    ChaoZers98/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 butdont geta 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, likeBasic, C++ or maybe Pascal? If you havent, i strongly suggest you do, because learningassembly 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 thingsyou have learned :)..

    The Binary System-----------------This is the computers "decimal system", its not like the decimal system thatwe use, let me show you an example of the difference.

    The DECIMAL System can use the values 0-9. Example. 64The BINARY System can use the values 0-1. Example. 01000000

    Theese two above values are the same. 01000000 in the binary system is thesame 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.

  • 8/7/2019 CTPart_1

    2/4

    $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 inthe 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 leftwould 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 00 0

    # 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4

    2 1In 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=8192Easy, 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. 64The 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

  • 8/7/2019 CTPart_1

    3/4

    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, becausemoste 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 thesection 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 itconsists 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 alreadyfigured 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)

  • 8/7/2019 CTPart_1

    4/4

    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 Bits11.4 Bytes

    Email&More----------Want to get in touch with me?My email is "[email protected]".My homepage is at "http://www.algonet.se/~chaozer/"

    You can also find me on IRC, almost everywhere, under the nickname ChaoZer.