1

I am currently learning about 6502 assembly. One of the documents I am learning about it from is a super mario bros. disassembly document. When I was reading the code I noticed part of the code had directives in it, here is that part:

   .index 8
   .mem 8

   .org $8000

Source: https://gist.github.com/1wErt3r/4048722

I know what directives are and what they do in other assembly languages but I have never heard of these directives. Is there some kind of reference document out there that has all of these 6502 directives on it with an explanation as to what they do?

  • Super Mario Bros, isn't that a SNES? This is on a 65816, not a 6502, right? – Will Hartung Oct 16 '18 at 0:28
4

One of the documents I am learning about it from is a super mario bros. disassembly document.

It would have been great, if you had included a link to the source, and especially for what system the source was meant - after all, Super Mario Bros. has been ported to many many different systems. Also, what assembler the source was meant for, as each has its own directives. Saves a lot of guessing.

.index 8
.mem 8

Well, this looks quite like a setup for a 65816 (*1), doesn't it? (*2)

So I guess the system is a SNES?

The 65816 can operate in various combinations of 8 and 16 bit wide data modes. These are set by the m (accumulator and Memory width) and x (indeX width) status register bits. Instructions behave differently depending on how these bits are set and code generation has to be made accordingly (*3). Since the assembler got no idea of the state of these bits (*4), the programmer must give some hint to the assembler.

.index 8 tells the assembler to generate code as if the index register (X/Y) width is set to 8 bit.

.mem 8 likely advises the assembler to generate code as if memory access is 8 bit wide.

.org $8000 now just means to assemble the following code starting at Address $8000.

I have never heard of these directives.

I've got some doubt, as ORG is about the most basic directive that every assembler does support.

Is there some kind of reference document out there that has all of these 6502 directives on it with an explanation as to what they do?

You may want to read a bit about assemblers in general and the manual for the one you are about to use - and eventually the one the source is meant for as well.

Here for example, a very brief introduction of the 65816 for already experienced 6502 programmers.

But then again, 6502.org is always a good start and should be your first stop for everything about the 6502. In particular the tutorials page. Some assembly required.


*1 - While WDC did try to standardise the 65816 assembler syntax (See section 6 of the datasheet), they did not provide any guideline for the new directives needed.

*2 - No, it isn't, as the later added source link shows, it's rather clean 6502 (even NMOS) code, but the original author used an 65816 assembler (x816, a somewhat dated assembler for MS-DOS) that requires these directives to make sure 8 bit code is produced. Adding references is a great way to avoid false guessing, isn't it?

*3 - Explaining all the details are way out of scope here, get some 65816 manual/lecture and spend some time reading.

*4 - They are dynamic at runtime and set/reset by SEP/REP instructions.

  • I have now included my source, according to the source it is a 6502 processor that is being used. Nevertheless, this response helps a lot! I will defiantly use the 65816 website as well when I decide to learn a 16 bit assembly language. – user115898 Oct 16 '18 at 1:07
  • 1
    @user115898 Nonetheless, he's using an 65816 assembler (Line 17: ;Assembles with x816.), so that's why the assembler had to be told to make 8 bit compatible code. – Raffzahn Oct 16 '18 at 1:20
2

What you're calling "directives" are not related to the actual CPU instructions. That is, they are not "6502 directives". Instead, each specific assembler had different ways of specifying things like code origin and memory configuration. There was some common notation, but the details of exactly what directives meant was contained in the assembler documentation.

  • 1
    I don't think the OP has any confusion about what an assembler directive is. – Wayne Conrad Oct 16 '18 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.