Jump to content
Sign in to follow this  
KAZ

I finally picked up some Assembly books!

Recommended Posts

From the library, I checked out three books:

 

6502 Machine and Assembly Language Programming, By Mike Smith

Copyright: 1984

 

6502 Assembly Language Programming For Apple, Commodore, And Atari Computers, By Christopher Lampton

Copyright: 1985

 

Programming the 65816 Including the 6502, 65C02 and 65802, By David Eyes and Ron Lichty

Copyright: 1986

 

None of the books were in the "main" section of books, I had to special request they go into another archival area where they keep old books.

 

And I am very serious about learning this stuff, have already read through the first chapter of one.

 

 

From Christopher Lampton's Book:

 

"In this book, we will asume from the outset that you are already familiar with at least one high-level programming language. It doesn't matter if this language is BASIC or Pascal or Logo or whatever, though we will occasionally draw examples from the BASIC language to illustrate certain programming principles."

 

And I knew this is what you were trying to do Nukey and all when telling me about BASIC. It resembles the English language more closely that assembly, and is easier to understand.

 

I like how they they say these are the high-level languages...this was before C++ even came out I'll bet.

 

 

So every night about an hour or so before I go to sleep, I'm gonna melt my brain with this stuff :)

 

I just hope my dreams are in an understandable language.

Share this post


Link to post
Share on other sites

BTW C++ is a lower-level language than Basic. The level refers to how much additional computation must be done to approach the problems in machine language (the only language computers really know). When a Basic (or any other language) line is executed, it is translated to machine language by the computer on-the-fly (which is why Basic is called an interpreter, and also why Basic is so much slower than other languages). With machine language, the program is already in it's native tongue.

Some Basic versions allow different techniques to make it lower-level (like using integer variables to speed up floating-point routines, or compiling the code all at once instead of line-by-line. Advan Basic does both of these, and you can even import Atari Basic programs into it)...but you are still dealing with generic routines that aren't made for speed.

Share this post


Link to post
Share on other sites

Yeah, I read that about how computers only understand binary (1's and 0's).

 

From the book: "They (high-level computer languages) are designed to be understood by human beings. To the computer, programs written in these languages are pure gibberish."

 

All programming languages eventually must be converted/translated into this machine language before it can be accepted.

 

I don't know BASIC, but I'm going to read this book anyways, and hopefully some of it will sink in.

 

So every so often if I do get confused while reading this stuff, I'll know who to ask.

 

Thanks!

Share this post


Link to post
Share on other sites

So here's what I've learned so far...

 

In the 6502 Microprocessor there are 6 registers:

 

A, SR, X, Y, SP, and PC

 

The first 5 have 8 bits (a bit being a series of 8 binary numbers)

The last one (PC) has 16 bits

 

There are commands in assembly language that can transfer (copy) the contents of one register into another

 

Some of these are:

TAX (transfer A to X)

TXA

TAY

TYA

 

Operation codes can go at the end of these commands (called op-codes)

 

All arithmetic procedures are done in the "A" register

 

Ok, but I have a question about binary...

Share this post


Link to post
Share on other sites

Here's where I was confused about binary:

 

from the book:

 

"If we counted the fingers of our two hands in binary, we would count like this:

1,10,11, 100, 101,110,111,1000,1001,1010"

 

So 11 would be a decimal of 3

100 would be a decimal of 4

 

1001 would be a decimal of 9, etc. etc.

 

But earlier on in the page he listed a binary number like this:

 

01011110

 

He says that it would translate into a decimal of 94!

 

I don't get it. I didn't think that a binary could start with a "0", using the counting I just wrote.

 

 

I DO know however, from earlier on, what a 1 and a 0 do in a microprocessor:

 

Each signal in a microprocessor can take on two forms:

A high voltage signal or a low voltage signal

a "1" is a high voltage

a "0" is a low voltage

 

And that's where I'm at in my learning :)

Share this post


Link to post
Share on other sites

Of course it can start with a 0. Just ignore it as it's preceeding :)

 

counting in binary Using 4 bits

 

0000 = 0

0001 = 1

0010 = 2

0011 = 3

0100 = 4

0101 = 5

0110 = 6

0111 = 7

1000 = 8

1001 etc.. (notice the above all started with 0's)

1010

1011

1100

1101

1110

1111

 

tada...

Share this post


Link to post
Share on other sites

KAZ,

 

With the number 01011110 you just ignore the first zero. just like if you were adding two decimal numbers like this:

 

0256

+0256

______

0512

 

If you weren't dealing with bytes you could write the binary number '01011110' like this:

 

'1011110'

 

But because your dealing with computers which work with bytes you have to deal with eight bits at a time even if the number you want is smaller such as the amount three, written in decimal as '3' and binary as '00000011'. You could write three in binary as '11' but not with a computer since it demands eight digit binary numbers.

 

Hope this helps and is not to simplistic.

 

Allan

Share this post


Link to post
Share on other sites
I don't get it.  I didn't think that a binary could start with a "0", using the counting I just wrote.  

 

 

It's traditional in binary to pad binary numbers out to an "even" number of bits. Since 1 byte is 8-bits, it's common to pad out to 8-digits. So 3 in decimal becomes 00000011. It's also common to see binary numbers padded to 4 digits which is called a nibble. The nice thing about breaking numbers into blocks of four digits is that it makes conversion to hexdecimal easier, because each group of four bits becomes 1 hex digit:

 

1111010000111000

 

1111 0100 0011 1000

F 4 3 8

 

$F438 in hex

 

Dan

Share this post


Link to post
Share on other sites

Thanks alot for the excellent answers, I do understand it pretty much completely now. Your explanations were really clear...

 

These numbering systems, even tho I understand them theoretically, will take some getting used to.

 

Hexadecimal (Base 16) is pretty straightforward:

 

0123456789ABCDEF

 

then you would continue:

 

10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20

 

I've actually had some "experience" with hexadecimal using things like Game Sharks and Game Genies for game systems.

A Game shark for instance only uses these hexadecimal numbers for the code

 

Sometimes a game will start glitching out if you use a code, and sometime you can actually see a number transform into a hexadecimal right on the video game screen.

 

It is neat to have seen that, and now to learn why it happens.

 

 

Well this programming stuff is hard to learn, but the rewards at the end should be worth it. I'm doing this as a hobby, and just for fun. I want to say that "I programmed game" sometime during my life.

 

It looks like this stuff is so deep, that you really can't just learn it off a couple documents online, you really need a good book like I have now.

Just reading the first couple chapters, and I'm further along in one night than I was in the last month. I just had to find the right reading material.

Share this post


Link to post
Share on other sites

So I just spent the last two hours reading more of this book.

 

So I read about the difference between JMP functions and Branch functions (BEQ for example)

 

I read about "zeroing out binary numbers", and how to "multiply" and "divide" numbers in memory locations, by using Rotate Right or Left commands (ROR and ROL).

 

And if this wasn't already intensely difficult to grasp, his next chapter "Addressing Modes" totally gave me a headache.

 

If it wasn't "Indirect Indexed Addressing" it was "Indexed Indirect Addressing".

 

Suffice to say I got absolutely nothing out of reading those 10 pages.

 

He did start talking about using text editors and about the actual assembling of programs (right up my alley with dasm).

 

Tho I'm not exactly finished reading this 100 page book, I'm moving on to my other two checked out books. Maybe I'll get through more chapters before becoming completely confused!

 

Wish me luck!

Share this post


Link to post
Share on other sites
And if this wasn't already intensely difficult to grasp, his next chapter "Addressing Modes" totally gave me a headache.

 

If it wasn't "Indirect Indexed Addressing" it was "Indexed Indirect Addressing".

Don't worry to much about "Indexed Indirect Addressing", it's very, very scarce used.

 

During my more than 15 years of programming for the 650x", I never needed it and in the disassemblies of 2600 games I saw yet, I can only remember Adventure where it occured once (just because the Y-register was used aready). But "Indirect Indexed Addressing" is what you will use very often.

Share this post


Link to post
Share on other sites

What an impossible problem I'm having now...

 

I'm trying to make a spreadsheet listing out binary numbers, hexadecimal numbers, and decimal numbers because this is the hardest problem I'm having, since I'm always staring at $A4 or $18

 

But it won't let me put in binary numbers like: 00000001 (7 0's)

I even tried changing the format of the column to TEXT, but that doesn't work either. It allows me to put a custom format in, but I don't what to put in.

 

If I write in: 00000001, the spreadsheet will turn this into just: 1

Share this post


Link to post
Share on other sites

Last question before I go to bed:

 

Did the Atari 2600 use:

 

the 6502 microprocessor

or the 6507 microprocessor

 

or both?

 

I would assume that studying on 6502 assembly language is still appropriate, as I think I read that the 6507 is only slightly different...more address lines, and no interrupt (whatever that means).

Share this post


Link to post
Share on other sites

Why are you making a spreadsheet? There should be some tables available online. Heck, here's one right here http://www.ascii.cl/conversion.htm.

Or you could just learn how to convert from binary to decimal to hex or in-between as it really isn't too hard.

Or of course you could use the Microsoft calculator on your pc (just set it to scientific mode) for number conversion goodness. :)

 

oh to get your Excel to show the formal "00000001" instead of "1"

 

1. Highlight the cells you want to affect

2. "Format" -- > "Cells"

3. Then under the "Number" tab select the category "Custom"

4. Under Type enter "00000000" (8 zeroes, without the quotes of course)

 

That should do it! :)

Share this post


Link to post
Share on other sites

Great! Thanks for the info. The custom numbering in Excel was perfect.

 

That table was pretty useful too...

 

The next book that I've been reading is much more "conversational" to read. He uses alot of analogies to how many memory locations there are.

 

He uses BASIC throughout the book to demonstrate assembly language/machine language. This means that I pretty much have to download atari800win, and see if I can get BASIC working.

 

I was hoping I'd be able to ignore BASIC entirely, since I won't be programming in its language anyway, but now it seems clear that I pretty much need to :(

 

Programs actually written in BASIC would run alot slower than those written in assembly. I think it is because assembly is closer to machine language than BASIC is, or actually because BASIC needs an interpreter program before it is ready to be transformed into machine language.

Share this post


Link to post
Share on other sites
Programs actually written in BASIC would run alot slower than those written in assembly.  I think it is because assembly is closer to machine language than BASIC is, or actually because BASIC needs an interpreter program before it is ready to be transformed into machine language.

1. Assembler is machine language, just written in are more human convenient way.

2. Yes, the interpreter is slowing BASIC down a lot. It's like running the compiler for every instruction while you run the program (and not only once before). On my C64 (same CPU as the 2600), assembler was 50 to 100(!) times faster than interpreted BASIC.

Share this post


Link to post
Share on other sites

In my spreadsheet I actually needed to stick an "N" before the "user defined" space.

 

So it would look like:

 

N00000000 (8 0's)

 

I'm having a rough time getting the formatting to stick for the hexadecimal.

 

At first I thought this was working:

 

N$00

 

Two letters works fine like this:

$FF works

as does

$BB

 

Also two numbers will work:

$89

$05

 

But when you try a number and a letter combination, it will switch one to a number:

 

$F3 will change to: $00

 

It is frustrating that the spreadsheet doesn't give me an option just to accept whatever I type into the columns. It is a "Corel Spreadsheet".

 

I've used Excel before, and it is just fine...but I don't have that currently installed, because I don't have the installation disk to it.

 

 

The reason I'm going to this trouble is because I want only the data that is most pertinent to me to be displayed, so that I can help myself figure out the numbering systems.

Share this post


Link to post
Share on other sites

is it worth to figure around with excel just because of this??? ;) my opinion is not... spend more time on training skills...

 

f.e. i have always a calculator (offline or online) with me while programming... so you can easily convert values...

 

$xy dec = x*16+y

 

$hilo = l*16+o+(h*16+i)*256

 

and if you use turbobasic xl (as recommend by me in another thread) you can easily use hex values in basic:

 

5 i=0

10 while peek(53279)=6:rem checks if START is pressed... could be "<>6" instead

20 poke $d01a,i

30 i=i+1

40 wend

50 print "finished... Heaven is great programmer... ;=)"

60 end

Share this post


Link to post
Share on other sites

And sooner or later you will get used to think in hex and binary codes. That helps a lot when are programming assembler.

Share this post


Link to post
Share on other sites

and btw... you can use decimal numbers in assemler as well...

 

lda #96 = lda #$60

 

lda #15 = lda #$0f

sta 53248 = sta $d000

 

the only restriction is that all 6502 registers are 8bit numbers so value range just between 0-255

 

of course mostly not in a monitor which has a single step assembler build in... but this is NOT an assembler... ;)

 

don't think too complicated when programming 6502... it is just a cpu. just 0 or 1s... the cpu is just doing what you want...

 

 

thomas...yes...thinking in 0101010101 is the key after a while... ;)

 

hve

 

ps. kaz...don't give up too early...1st try to change colors in assembler...and so on...

 

f.e.

atari800:

 

org $0600

colbk = $d01a

 

start ldx #0

loop stx colbk

inx

jmp loop

 

(this was my hello world... ;=))

Share this post


Link to post
Share on other sites
and btw... you can use decimal numbers in assemler as well...

 

lda #96 = lda #$60

 

lda #15 = lda #$0f

sta 53248 = sta $d000

 

Yes, I see...using equates in the first part of the assembly code. Assigning something to another, so it remains that throughout the rest of the code.

 

I sort finished the first book I was reading, and although my brain is still frying from it, I did get some concepts in my head.

 

I became familiar with Branch codes. It looks for a certain flag to decide whether to jump to a different address. I learned that hexadecimal numbers can be added together longhand, just using 0-F instead of 0-9

 

12+

13

___

25

 

1A+

33

___

4D

 

A went to D

 

I'm not gonna give up...I think I know a little more than when I started. When I look at a long passage of code, I sometimes panick! What the hell is that? Then I start recognizing some familiar mnemonics like:

STA JMP TAX AND

 

Understanding assembly coding is fine on the one hand, but then I have to specifically apply it to the 6502 that SITS IN THE ATARI 2600.

That microprocessor is in Commodore machines for example.

 

And I finally figured out that "Kernal" refers to the Commodore 64 operating system. But it has taken on a different meaning over time also I think.

Share this post


Link to post
Share on other sites

Hi Kaz! Nice to see you so motivated...

 

and btw... you can use decimal numbers in assemler as well...

 

lda #96 = lda #$60

 

lda #15 = lda #$0f

sta 53248 = sta $d000

 

Yes, I see...using equates in the first part of the assembly code. Assigning something to another, so it remains that throughout the rest of the code.

 

Actually it's not about the equates. Heaven/TQA meant that writing LDA #96 is the same as writing LDA #$60 ... you just take out the $ sign and convert the value to decimal..

 

Ciao and keep up the good work!

Rasty.-

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...