So what happened when the compiler ran?? It took our assembly code and converted it into machine code and stored it in a prg File that the commodore could read. The commodore loaded the file, where it was instructed to, starting at C000.
Lets see what the code looks like, waiting to be executed
Upon being loaded the computer waits with a ready prompt. You will want to execute the program at its memory location 49152 (HEX $C000), but before we do that lets look at the code in memory
(C:$c051) m c000 c110
>C:c000 a9 93 20 d2 ff a9 01 8d 15 d0 a9 aa 8d 00 d0 a9 .. .............
>C:c010 8f 8d 01 d0 a9 0b 8d f8 07 a2 00 20 22 c0 20 2e ........... ". .
>C:c020 c0 60 bd 43 c0 9d c0 02 e8 e0 40 d0 f5 60 a9 01 .`.C......@..`..
>C:c030 8d 10 d0 a9 3b 8d 00 d0 a9 32 8d 01 d0 a9 f2 8d ....;....2......
>C:c040 27 d0 60 03 ff 00 07 ff 80 0f ff 80 1f 83 80 3e '.`............>
>C:c050 00 80 7c 00 7f 78 00 7e f8 00 7c f0 00 78 f0 00 ..|..x.~..|..x..
>C:c060 70 f0 00 00 f0 00 70 f0 00 78 f8 00 7c 78 00 7e p.....p..x..|x.~
>C:c070 7c 00 7f 3e 00 80 1f 83 80 0f ff 80 07 ff 80 03 |..>............
>C:c080 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
What we see here is a collection of OPCODES and values
The OPCODE is a processor instruction, each one may include zero or several values after it, depending on the situation.
Lets look at the code highlighted , Red are OPCODES green are values
(C:$c051) m c000 c110
>C:c000 a9 93 20 d2 ff a9 01 8d 15 d0 a9 aa 8d 00 d0 a9 .. .............
>C:c010 8f 8d 01 d0 a9 0b 8d f8 07 a2 00 20 22 c0 20 2e ........... ". .
>C:c020 c0 60 bd 43 c0 9d c0 02 e8 e0 40 d0 f5 60 a9 01 .`.C......@..`..
>C:c030 8d 10 d0 a9 3b 8d 00 d0 a9 32 8d 01 d0 a9 f2 8d ....;....2......
>C:c040 27 d0 60 03 ff 00 07 ff 80 0f ff 80 1f 83 80 3e '.`............>
>C:c050 00 80 7c 00 7f 78 00 7e f8 00 7c f0 00 78 f0 00 ..|..x.~..|..x..
>C:c060 70 f0 00 00 f0 00 70 f0 00 78 f8 00 7c 78 00 7e p.....p..x..|x.~
>C:c070 7c 00 7f 3e 00 80 1f 83 80 0f ff 80 07 ff 80 03 |..>............
>C:c080 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
We start with
[A9] - Load accumulator , with the following value 93
[20] - Jump to Sub Routine, followed by D2 and FF. The 6502 is Little Endian and writes in memory addresses backwards. It is actually FF D2, our CHROUT routine, and comes back to the next instruction after the JSR
[A9] - Load accumulator , with the following value 01
[8D] - Store Accumulator to 15 D0, which we know as $D015
[A9] - Load accumulator , with the following value AA
[8D] - Store Accumulator to 00 D0, which we know as $D000
[A9] - Load accumulator , with the following value 8F
[8D] - Store Accumulator to 01 D0, which we know as $D001
[A9] - Load accumulator , with the following value 0B
[8D] - Store Accumulator to F8 07, which we know as $07F8
[A2] - Load X register , with the following value 00
[20] - Jump to Sub Routine to 22 C0, which we know as $C022 (SPR0LOADLOOP)
[20] - Jump to Sub Routine to 2E C0, which we know as $C02E (MOVEANDCOLOR)
[60] - Return from Sub Routine
[BD] - Load accumulator ABSOLUTE,X with the following value C043 the beginning of sprite data
[9D] - Store accumulator ABSOLUTE,X to the area 02C0 the beginning of sprite 64k block
[E8] - Increment X (X=X+1)
[E0] - Compare X to hex 40
[D0] - Branch on not equal, to relative address F5 known as -11(decimal) $C022 from current PC
[60] - Return from Sub Routine
[A9] - Load accumulator , with the following value 01
[8D] - Store Accumulator to 10 D0, which we know as $D010
[A9] - Load accumulator , with the following value 3B
[8D] - Store Accumulator to 00 D0, which we know as $D000
[A9] - Load accumulator , with the following value 32
[8D] - Store Accumulator to 01 D0, which we know as $D001
[A9] - Load accumulator , with the following value F2
[8D] - Store Accumulator to 27 D0, which we know as $D027
[60] - Return from Sub Routine
See the highlighted blue segment, thats out sprite0 data directly following the RTS instruction [60] Starting at $C041to $C082
If we break this down any further, we will literally be left with Binary Machine code of On's and OFFs
Just to display this example, the final code that the machine would read would look like this, I adding the HEX above for view ability, showing the first 5 bytes of the program
A9 93 20 D2 FF
10101001 10010011 00100000 11010010 11111111
NEXT----->
Understanding 6502 assembly on the Commodore 64 - (8) Inputs in Assembly
Table of contents
Lets see what the code looks like, waiting to be executed
Upon being loaded the computer waits with a ready prompt. You will want to execute the program at its memory location 49152 (HEX $C000), but before we do that lets look at the code in memory
>C:c000 a9 93 20 d2 ff a9 01 8d 15 d0 a9 aa 8d 00 d0 a9 .. .............
>C:c010 8f 8d 01 d0 a9 0b 8d f8 07 a2 00 20 22 c0 20 2e ........... ". .
>C:c020 c0 60 bd 43 c0 9d c0 02 e8 e0 40 d0 f5 60 a9 01 .`.C......@..`..
>C:c030 8d 10 d0 a9 3b 8d 00 d0 a9 32 8d 01 d0 a9 f2 8d ....;....2......
>C:c040 27 d0 60 03 ff 00 07 ff 80 0f ff 80 1f 83 80 3e '.`............>
>C:c050 00 80 7c 00 7f 78 00 7e f8 00 7c f0 00 78 f0 00 ..|..x.~..|..x..
>C:c060 70 f0 00 00 f0 00 70 f0 00 78 f8 00 7c 78 00 7e p.....p..x..|x.~
>C:c070 7c 00 7f 3e 00 80 1f 83 80 0f ff 80 07 ff 80 03 |..>............
>C:c080 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
What we see here is a collection of OPCODES and values
The OPCODE is a processor instruction, each one may include zero or several values after it, depending on the situation.
Lets look at the code highlighted , Red are OPCODES green are values
(C:$c051) m c000 c110
>C:c000 a9 93 20 d2 ff a9 01 8d 15 d0 a9 aa 8d 00 d0 a9 .. .............
>C:c010 8f 8d 01 d0 a9 0b 8d f8 07 a2 00 20 22 c0 20 2e ........... ". .
>C:c020 c0 60 bd 43 c0 9d c0 02 e8 e0 40 d0 f5 60 a9 01 .`.C......@..`..
>C:c030 8d 10 d0 a9 3b 8d 00 d0 a9 32 8d 01 d0 a9 f2 8d ....;....2......
>C:c040 27 d0 60 03 ff 00 07 ff 80 0f ff 80 1f 83 80 3e '.`............>
>C:c050 00 80 7c 00 7f 78 00 7e f8 00 7c f0 00 78 f0 00 ..|..x.~..|..x..
>C:c060 70 f0 00 00 f0 00 70 f0 00 78 f8 00 7c 78 00 7e p.....p..x..|x.~
>C:c070 7c 00 7f 3e 00 80 1f 83 80 0f ff 80 07 ff 80 03 |..>............
>C:c080 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
We start with
[A9] - Load accumulator , with the following value 93
[20] - Jump to Sub Routine, followed by D2 and FF. The 6502 is Little Endian and writes in memory addresses backwards. It is actually FF D2, our CHROUT routine, and comes back to the next instruction after the JSR
[A9] - Load accumulator , with the following value 01
[8D] - Store Accumulator to 15 D0, which we know as $D015
[A9] - Load accumulator , with the following value AA
[8D] - Store Accumulator to 00 D0, which we know as $D000
[A9] - Load accumulator , with the following value 8F
[8D] - Store Accumulator to 01 D0, which we know as $D001
[A9] - Load accumulator , with the following value 0B
[8D] - Store Accumulator to F8 07, which we know as $07F8
[A2] - Load X register , with the following value 00
[20] - Jump to Sub Routine to 22 C0, which we know as $C022 (SPR0LOADLOOP)
[20] - Jump to Sub Routine to 2E C0, which we know as $C02E (MOVEANDCOLOR)
[60] - Return from Sub Routine
[BD] - Load accumulator ABSOLUTE,X with the following value C043 the beginning of sprite data
[9D] - Store accumulator ABSOLUTE,X to the area 02C0 the beginning of sprite 64k block
[E8] - Increment X (X=X+1)
[E0] - Compare X to hex 40
[D0] - Branch on not equal, to relative address F5 known as -11(decimal) $C022 from current PC
[60] - Return from Sub Routine
[A9] - Load accumulator , with the following value 01
[8D] - Store Accumulator to 10 D0, which we know as $D010
[A9] - Load accumulator , with the following value 3B
[8D] - Store Accumulator to 00 D0, which we know as $D000
[A9] - Load accumulator , with the following value 32
[8D] - Store Accumulator to 01 D0, which we know as $D001
[A9] - Load accumulator , with the following value F2
[8D] - Store Accumulator to 27 D0, which we know as $D027
[60] - Return from Sub Routine
See the highlighted blue segment, thats out sprite0 data directly following the RTS instruction [60] Starting at $C041to $C082
If we break this down any further, we will literally be left with Binary Machine code of On's and OFFs
Just to display this example, the final code that the machine would read would look like this, I adding the HEX above for view ability, showing the first 5 bytes of the program
A9 93 20 D2 FF
10101001 10010011 00100000 11010010 11111111
NEXT----->
Understanding 6502 assembly on the Commodore 64 - (8) Inputs in Assembly
Table of contents
No comments:
Post a Comment