+  RHDN Forum Archive
|-+  Romhacking
| |-+  General Romhacking
| | |-+  Assembly programs
Pages: [1]
Author Topic: Assembly programs  (Read 642 times)
hippiejake
Guest
« on: October 22, 2006, 02:15:57 am »

Hello.
I decided that I'd give learning 6502 assembly another try, since I just learned how to use DOS to a decent extent[thanks creaothceann]. I've got a couple disassemblers working, Tracer and something simply called 6502 Disassembler. I disassembled a SMB3 rom on each. Then my problem arose: I couldn't get an assembler to work. WLA-DX said "not enough memory." o.0 From what I understand, 6502 and 65816 are almost identical. So I tried byuu's xkas, and it appears that BOTH disassemblers gave an odd dump, because I got several hundred "invalid opcode" errors before I closed it.
This is a sample of the dump from Tracer:
Code:
03/B0B3: B4 01        LDY $01,X
03/B0B5: 6F 0C E3 13  ADC $13E30C
03/B0B9: 0C 0A 70     TSB $700A
03/B0BC: 03 73        ORA $73,S
03/B0BE: 2F 01 C1 2F  AND $2FC101
03/B0C2: 0D C6 FF     ORA $FFC6
03/B0C5: 00 00        BRK $00

And a snippet from "6502 Disasembler"
Code:
00017218: BD8079 LDA $7980,X
0001721B: E506 SBC $06
0001721D: D006 BNE $06
0001721F: A505 LDA $05
00017221: C941 CMP #$41

I'm really confused. I guess when it disassembles, it's not in the right form to assemble again. I also noticed that these files use X and Y. Am I confused again, or am I correct that 6502 only has the accumulator? I had hoped that once I had learned how to use the damn MS-DOS shell that I would have no problems assembling and disassembling, but this pops up. Am I using the wrong disassembler, assembler, both, or am I just retarded?
I would greatly appreciate any help. Thanks.
tomaitheous
Guest
« Reply #1 on: October 22, 2006, 02:32:18 am »

You need to remove the address and opcode/operand data and just keep the mnemonics.

 
Code:
lda $7980, x
 sbc $06

 You can also use MagicKit assembler as long as you avoid PC Engine specific instructions or 65c02 instructions.  The 65c02 has a some addressing modes that aren't in the 6502. WLA-DX would probably be better, but I'm not sure if it supports NES illegal opcodes.

The 6502/65c02 and other variants with the same core (WDC/Rockwell/Hudson/Mitsubishi) have the Accumulator register and two index registers X and Y - as well as SP, FLAG, PC regs.

 You want to be careful about the starting disassemble address and gaps between code that cause alignment issues. Also, some assemblers require different syntax for zeropage addressing.

Opcode $E5 uses ZP addressing:

 sbc $06  is sbc <$06 in Magickit

« Last Edit: October 22, 2006, 02:38:31 am by tomaitheous »
Spikeman
Guest
« Reply #2 on: October 22, 2006, 02:34:06 am »

I'm not really experienced with assembly on these processors, but it looks like the tracer outputted the address of the code and it's value in hex as well as the code. To compile it you should just have things like this (using your examples):

Code:
LDY $01,X
ADC $13E30C
TSB $700A
ORA $73,S
AND $2FC101
ORA $FFC6
BRK $00

Code:
LDA $7980,X
SBC $06
BNE $06
LDA $05
CMP #$41
hippiejake
Guest
« Reply #3 on: October 22, 2006, 02:46:51 am »

Alright, thanks. It's like 1PM here so I've got to get some sleep, but I'll definitely check this out tomorrow. Wink
creaothceann
Guest
« Reply #4 on: October 22, 2006, 03:58:32 am »

Quote from: hippiejake on October 22, 2006, 02:15:57 am
WLA-DX said "not enough memory."

You could try emulators like DOSBox or MS Virtual PC.

Note that working in DOS is much easier with a file manager like Norton Commander.
RedComet
Guest
« Reply #5 on: October 22, 2006, 08:53:05 am »

Tracer isn't to NES friendly. It's good for getting a general idea, but you'll want to open up the rom in a debugger and fine tune your understanding through trace logs and stepping into the code.
KingMike
Guest
« Reply #6 on: October 22, 2006, 11:46:25 am »

Another thing is that the NES can only handle 16-bit addressing, so instructions with 3-byte addresses won't work.
Also, doing a full ROM disassembly isn't a very good idea, since it will also try to decode data within the code, very possibly screwing up whatever real code followed.
I could go on more about how Tracer's code isn't easily reassemblable, but I don't have time. Sad
tomaitheous
Guest
« Reply #7 on: October 22, 2006, 12:18:49 pm »

Code:
03/B0B5: 6F 0C E3 13  ADC $13E30C
Code:
03/B0BE: 2F 01 C1 2F  AND $2FC101

Didn't even notice those. That's definitely an incorrect disassembley for NES (greater than 16bit address).

Oh yeah, Magickit has a NES assembler packaged with it too - nesasm.exe. I totally forgot about that.

« Last Edit: October 22, 2006, 12:28:55 pm by tomaitheous »
Pages: [1]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC