Jump to content
IGNORED

What does "sta" and "lda" mean?


Recommended Posts

LDA and STA are two very common 6502 instructions. LDA being LoaD Accumulator and STA STore Accumulator. LDA is used to load a new value into the accumulator from a variety of sources (immediate, memory, or indexed memory). STA allows you to store the contents of the accumulator to a memory location. The Accumulator is the main register of the 6502 and is used to perform many numerical operations. If you are interested in learning 6502 assembly, you should take a look at Machine Language for Beginners, it's a great read for anyone with programming experience, but minimal knowledge about processors. Chapter 6 has a summary of all the instructions, where you can look up others if you're curious.

Link to comment
Share on other sites

Also, does anyone have any links on converting numbers to Atari hex? I'm asking because all hex converters I've come across have completely different hex results than what the Atari uses.

 

For instance, in this tutorial code it says that "-1" is "#$F0" in assembly, but on the online converters it says it's "00 01" and that "F0" is "240".

 

Mind confuzzled.

Link to comment
Share on other sites

Also, does anyone have any links on converting numbers to Atari hex? I'm asking because all hex converters I've come across have completely different hex results than what the Atari uses.

 

For instance, in this tutorial code it says that "-1" is "#$F0" in assembly, but on the online converters it says it's "00 01" and that "F0" is "240".

 

Mind confuzzled.

 

6502 can handle only 8 bits of data. So zero is $00 and minus one is $FF, alternatively you can see it as 255 decimal.

 

The point is that if you have a value of $03 and you add it $FF then you'll have $02 (3 plus -1 equals 2) because this trick ;)

Link to comment
Share on other sites

Hex is hex, there's no 'atari' hex. Hex is four bits per character. Atari uses 8 bit bytes. Therefore, two hex characters make up one atari byte. 'Hex' stands for hexadecimal, meaning base 16, meaning numerals 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. So a hex number like $03 ( the dollar means its hex ) means a hex value of 0 followed by a hex value of 3. In binary, this would look like 0000 0011. A hex value of $A1 would look like this in binary : 1010 ( ie., decimal 10 or hex $A ) followed by 0001.

 

Negative numbers are represented using two's complement ( you can google that ), so a -1 decimal looks like 1111 1111 binary, which looks like $FF in hex. All these expressions 'mean' the same bit pattern : -1,$FF,255,11111111

Edited by danwinslow
Link to comment
Share on other sites

 

6502 can handle only 8 bits of data. So zero is $00 and minus one is $FF, alternatively you can see it as 255 decimal.

 

The point is that if you have a value of $03 and you add it $FF then you'll have $02 (3 plus -1 equals 2) because this trick ;)

 

So how come "255" equals "-1" in this case? So, are you saying that there's a point where half way through the 6502's numbers there's a point where "128" is actually "-128"?

Could it be seen as two 128s but the second version is minus numbers?

 

So is $7F equal to 127, but $80 is equal to -128?

Link to comment
Share on other sites

 

So how come "255" equals "-1" in this case? So, are you saying that there's a point where half way through the 6502's numbers there's a point where "128" is actually "-128"?

Could it be seen as two 128s but the second version is minus numbers?

 

So is $7F equal to 127, but $80 is equal to -128?

 

You're right with both interpretations, $81 is -127 or 129 depending on context.

 

You choose if your program or some special variable of yours is using signed or unsigned numbers, the processor doesn't note the difference.

 

It simplifies enormously programming matters specially when you start handling 16-bit numbers using two bytes, the lowest byte always is unsigned and the higher byte is signed or unsigned per your requirements.

Link to comment
Share on other sites

Everything just depends on how your program is set up to interpret different numbers. I've personally never used a negative number in any of my games.

 

If you're interested in binary representations of negative numbers, look up sign magnitude notation and 2's complement. Of course, these binary representations can be converted to other bases, such as hex or decimal, so that explains why FF could be either 255 decimal or -1 decimal, which is it's 2's complement interpretation.

Link to comment
Share on other sites

I realise how much I don't know. Do the signed and unsigned numbers have something to do with the A, X and Y? Do you tell the 6502 what number draws the line between being positive and negative?

No, and No.

 

In a way, there's no such thing as a negative number to the computer, its all just eight bits. 255 is the same as 11111111 is the same as $FF. You can interpret 11111111 as -1, depending on the context, but to the computer it's stil just 11111111.

 

The numbers roll over at 255, since all eight bits are used. 255+1=0 ( but the carry flag gets set ).

Link to comment
Share on other sites

Ah, okay then. So, with out minus numbers, how can you move to the right using HMOVE?

 

Use one of the commonly available routines, like this http://atariage.com/forums/topic/198465-i-want-to-keep-learning-a2600-programming-but-im-stuck/?do=findComment&comment=2529970

 

Note it uses negative numbers to calculate the final position, but you don't need to think about it at this point.

Edited by nanochess
  • Like 1
Link to comment
Share on other sites

Ah, okay then. So, with out minus numbers, how can you move to the right using HMOVE?

You wouldn't store say a -3 to HMOVE to reset it's position 3 clocks to the right, you'd store 11011111b (which is 223d, or DFh). This is covered in the Stella Programmer's Guide. Here is a link the table of values HMOVE interprets:

 

http://www.alienbill.com/2600/101/docs/stella.html#HMOVE

 

It's all about what the hardware or functions in your program that numbers are passed to interpret them as. Think of them as 256 values that could mean anything.

  • Like 2
Link to comment
Share on other sites

On the Programmer's Guide it says 1101. What do the extra 1111b mean? Is that just filling in for the byte?

 

On the world of Atari's TIA, there are several bits in registers that aren't used, you can fill them with zeros or ones.

 

The HMOVE registers use bits 7-4 and bits not used are 3-0, so you can use 11011111b or 11010000b as you like.

Edited by nanochess
Link to comment
Share on other sites

On the Programmer's Guide it says 1101. What do the extra 1111b mean? Is that just filling in for the byte?

The head of the table specifies bits D4-D7, which are the 4 most significant bits. The other 4 (D0-D3) can actually be anything, because the hardware ignores them. So storing 11010000 would do the same thing as 11010001 and 11010010, and so on. As long as D4-D7 are set as you want them, the others can contain any value.

 

Edit:

Ha, we keep posting at the same time

Edited by Wickeycolumbus
Link to comment
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...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...