MACHINE LANGUAGE TUTORIAL DISK

---
Master Index Current Directory Index Go to SkepticTank Go to Human Rights activist Keith Henson Go to Scientology cult

Skeptic Tank!

*************************************** * * * * * MACHINE LANGUAGE TUTORIAL DISK * * * * WRITTEN BY DR. FIRMWARE * * * * * *************************************** PART II Machine language command structure. Even though this sounds complicated, the structure of machine language commands is quite simple. The command is one to three bytes long and consists of two sections, the operator and the arguement. The operator is always one byte long and the arguement is either zero, one or two bytes long. If the arguement is zero bytes long, then it is said that there is no arguement for that command. The accumulator The accumulator is the primary register in the 6502 microprocessor. It is an 8 bit register, which means that it can handle only eight bits at a time or the numbers from zero to 255. To put numbers into the accumulator, we use a command called LDA which stands for LoaD Accumulator. This command takes the value generated by the arguemant and places it into the accumulator. Addressing modes Addressing modes are very important. These tell the computer how to deal with the arguement that it recieves. We will only be dealing with two modes for the present, immeadiate, and absolute. In immeadiate addressing mode, the LDA command load the accummulator with the actual value of the arguement. Suppose that we wanted to load the value $6F into the accumulator. We would do this by telling the microprocessor to 'LDA #$6F'. That is assembly language. In actual fact, the code used by the microprocessor would represent it as '$A9 $6F'. The $A9 tells the microprocessor that you want to load the accumulator in immeadiate addressing mode. The $6F is the arguement and is treated as described above. So then, the number $6F is put directly into the accumulator. The LDA command in immeadiate addressing mode is two bytes long. The first byte being the operator ($A9) and the second being the arguement. Memory locations. The Apple computer has 2~16 memory locations. Each memory location is 8 bits large. Each memory location can be referenced by a 4 digit hex number. A four digit hex number is 2 bytes long and can be cut in half into two separate bytes. The byte on the left is more significant than the one on the right, so the one on the left is called the Most Significant Byte (MSB) and the one on the right is the Least Significant Byte (LSB). In absolute addressing mode, the LDA command takes the arguement as an address and then takes the value held in that address and transfers it to the accumulator. The arguement is two bytes long and it forms the address LSB first and MSB second. The address is in effect backwards. Say you wanted to load the accumulator with whatever was in location $456D. The operator is $AD, this is followed by the LSB which is $6D, and finally the MSB, $45. Storing the accumulator. To move the contents of the accumulator to some other memory location, we use the command STA, which stands for STore Accumulator. The STA command has an absolute addressing mode. The hex operator is $8D and it is followed by the LSB and MSB, in that order. After the command is executed, the accummulator still contains the value. Now we can make a tiny program to store the value $8D into location $2000. First, we have to load it into the accumulator. To do this, we'll load the $8D into the accumulator through the LDA immeadiate command. So, then we'll store the accumulator into $2000 while it contains our value using the STA absolute command. In assembly language, our program looks like this: LDA #$8D STA $2000 RTS Note: the '#' indicates that the command is in immediate addressing mode. The RTS is going to be used as a general 'end' command for now, until I can explain it's actual usage. This assembly language version is not understandable by the microprocessor. It has to be translated into hex codes. This translation is normally done by an assenbly program, but since this is a short program, we'll do it by hand. We are going to put this program at location $300-$306. This area can be used for short programs as $300-$3b0 is free memory space. An extended memory map will be included in a later edition. LDA #$8d --> $A9 8D STA $2000 --> $8D 00 20 RTS --> $60 hex location contents --------------------------- $300 $A9 $301 $8D $302 $8D $303 $00 $304 $20 $305 $60 The program can be entered into memory using the BASIC POKE command. $300 is equal to 768 and the rest of the hex numbers you should be able to convert into decimal yourselves. This concludes PART II of the series. Coming next: X and Y registers. ======================================= DR. FIRMWARE, 1985. I CAN BE REACHED ON TESTY, 514-332-6852 OR ON TRANSFERS AE, 514-738-1247 =======================================

---

E-Mail Fredric L. Rice / The Skeptic Tank