Jump to content
Sign in to follow this  
  • entries
  • comments
  • views

Having to learn Machine Language in my own unique way



I stayed with the tutorials on Random's website for a couple of hours and got to lesson 12 understanding most of what I was doing but I found myself constantly confused at some portions of the code I would be looking at.


While the tutorial I'm currently going through is good, and very informative, I feel it was missing some key elements/just brush over them with minor detail that I still need to study up on and get clarification on as well. The following information I feel should have been the first thing taught and really hammered into the student, if you have a solid understanding of the following, I feel the rest will come very easily.


From my current understanding, which could be incorrect as I am still learning, the 6502 has 3 registers (I consider them variables, but that is just how I think about it) that you can us, A, X, and Y. The operations you have for each variable is as follows:



sta <- store a into the following

lda <- load a with the following

ina <- increment value stored in variable a

dea <- decrement value stored in variable a

A has other oprerations as well, and as the author discribed it, its the "workhorse" of the 3 registers available on the 6502 (really the 6507) CPU.



stx <- store x into the following

ldx <- load a with the following

inx <- increment value stored in variable x

dex <- decrement value stored in variable x



sty <- store x in the following

ldy <- load x with the following

iny <- increment value stored in variable y

dey <- decrement value stored in variable y


The other thing I'm still trying to wrap my mind around completed is how you use these registers with the registers from vcs.h. Such as the following:


ldx #0


I guess for me I have to reverse my thinking of how these registers work. I'll explain with the following example:


ldx #0 really means the following in x = 0
stx COLUBK really means the following COLUBK = x


However in my mind, I would think ldx would be used to retrieve the value of x. Same thing for the stx which really means "store x in" and is used to take the value in the register x and put it int he following register COLUBK, in my mind it would be reverse, I want to think of it as storing a value into x.


While this might seem minor and trivial, it was a small yet important concept for me to wrap my head around last night and this morning. I guess this just shows how I have to learn different from others which is fine.


The more I think about trying to program in machine language, the more I'm applying natural language to each statement to help me retain this information in my memory.


ldx is "load x with the following"

stx is "store x in the following"


I'm thinking of going through my books tonight to learn how loops, if statements and other basic operations that are pretty much universal in all languages, meaning Java, BASIC, C, Assembly all have IF statements its just learning the way the specific language requires you to setup the statement, before I continue with the rest of the 2600 programming tutorial on Randoms website. I think I will have a stronger grasp of the Machine Language if I go about it in this manor.


If I've made any glaring errors in this please let me know so I can correct myself and learn!





Recommended Comments

Unfortunately, 'INA' and 'DEA' are not 6502 instructions.


So you would have to first store the value of A into X or Y, call dex/dey or inx, iny and then load the value of X back into A correct? How would that look in Machine Language?

Share this comment

Link to comment

lda #10 ; a = 10

tax ; x = 10 (Transfer A to X)

inx ; x = 11

txa ; a = 11 (Transfer X to A)



you can also change values in RAM w/out having to load them into a register:

inc $80 (value in location $0080 just increased by 1)

dec $81 (value in location $0081 just decrease by 1)

  • Like 1

Share this comment

Link to comment
lda #10 ; a = 10tax ; x = 10 (Transfer A to X)inx ; x = 11txa ; a = 11 (Transfer X to A) you can also change values in RAM w/out having to load them into a register:inc $80 (value in location $0080 just increased by 1)dec $81 (value in location $0081 just decrease by 1)


Thank you Spiceware! I need to find and print off a document that has all the opcodes that the 2600 has. Opcodes is the correct term right?

Share this comment

Link to comment

Another way to increment A:

CLC			  ; carry = 0
ADC #1		 ; A = (A + carry + 1) mod 255, carry = (A + carry + 1) div 256


SEC			  ; carry = 1
ADC #1		 ; A = (A + carry + 0) mod 255, carry = (A + carry + 0) div 256

If you know the value of the carry flag, then that instruction isn't required. Decrement is left as an exercise for the reader (just watch the carry flag).

Share this comment

Link to comment
Add a comment...

×   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.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...