0

im trying to write a program that implements modifying memory and then disassembling it with Assembly Language. Currently ive got the basics set up, as in it'll take the commands and you can modify the memory, and it'll accept the LD opcodes, but im really struggling to figure out how i can essentially error trap some problems. I want to be able to say for example, with an LDAA Mnemonic opcode of 0xB6 for extending addressing mode - make it so that if another opcode is detected within 2 bytes after the 0xB6 it will just ignore them and put a (???), then look for the next opcode to disassemble.

I don't even know if this is the right way to go about it honestly, as it leaves it open to missing say an 18 to denote an IND,Y addressing mode. Regardless, i need help figuring out what the best way to implement this sort of error trapping routine is. Because i'll only have to do it for all of them as far as im aware. Id rather not have to type out each opcode for them each time to tell them to just print ???, but im unable to use for loops in c90.

Any advice and help would be greatly appreciated!

I tried to make a grouping of the opcodes so that i could simply write 'opcode' and have it check the next bytes against all of them without having to list each of them every time when writing, but i dont know if thats possible and if it is, i dont know how. I did write them out manually as well to give it a go, but couldnt get it to actually recognise any of the opcodes so it would continue to give a disassembled string like 'LDAA$A6FF.

  • 1
    I'm confused. Are you writing a disassembler? Why would it matter if there is another opcode within two bytes of 0xB6? If 0xB6 has a two-byte address, then the two bytes are always an address, right? – Tim Roberts Aug 12 '23 at 03:55
  • Machine code with variable-length instructions is a byte stream that's not self-synchronizing for most ISAs: you need to know a correct starting point to decode and find instruction boundaries. You can't just scan every byte for an opcode you're looking for because as you say, those bytes can appear as operands, not opcdes. x86 assembly is the same way, but hopefully 68hc11 is a lot easier to decode than modern x86. – Peter Cordes Aug 12 '23 at 04:05
  • Also, C90 does have `for` loops. You can't declare variables inside the `for` itself in strict C90, so you need `int i; ...; for (i=0 ; i – Peter Cordes Aug 12 '23 at 04:07

0 Answers0