PrintLogo

Disassembling and Assembling 8048 Binaries




In this article, I showed how to compile D52. In this article, I showed how to disassemble and assemble 8048 code. Well, it turns out that if you try and do this same technique with Odyssey 2 binaries, you run into problems. After struggling, I found a disassembler/assembler here that works well for this. I also put a copy of the source up here. Let's compile:

usr-1@wrk-1 usr-1 $ ls asm*
asm48-0.0-src.tar.gz
usr-1@wrk-1 usr-1 $ tar -xzf asm*.gz
usr-1@wrk-1 usr-1 $ cd asm*
usr-1@wrk-1 asm48-0.0 $ ls
8039dasm.c  asm48.c  err.c     ihex.c         parse.y  symtab.
Makefile    asm48.h  expr.c    instruction.c  pool.c   test.as
README      asmdasm  getopt.c  lex.l          runtest  test2.a
usr-1@wrk-1 asm48-0.0 $ 
ne@wrk-1 asm48-0.0 $ make
bison -d parse.y
gcc  -O -Wall -DHAVE_GETOPT -c parse.tab.c -o parse.o
flex lex.l
gcc  -O -Wall -DHAVE_GETOPT -c lex.yy.c -o lex.o
lex.yy.c:1658: warning: `yyunput' defined but not used
gcc  -O -Wall -DHAVE_GETOPT -c asm48.c
gcc  -O -Wall -DHAVE_GETOPT -c instruction.c
gcc  -O -Wall -DHAVE_GETOPT -c expr.c
gcc  -O -Wall -DHAVE_GETOPT -c symtab.c
gcc  -O -Wall -DHAVE_GETOPT -c pool.c
gcc  -O -Wall -DHAVE_GETOPT -c err.c
gcc  -O -Wall -DHAVE_GETOPT -c ihex.c
gcc -o asm48 parse.o lex.o asm48.o instruction.o expr.o symtab.o pool.o err.o ihex.o  -lfl
gcc  -O -Wall -DHAVE_GETOPT -c 8039dasm.c
gcc -o 8039dasm 8039dasm.o
usr-1@wrk-1 asm48-0.0 $ 

Let's grab an Odyssey 2 ROM image from here, and disassemble and assemble it:

usr-1@wrk-1 asm48-0.0 $ ./8039dasm AMOKPD.BIN 0 4096 > amok.asm
usr-1@wrk-1 asm48-0.0 $ head amok.asm
jmp  $02C3
jmp  $0009
call $040C
jmp  $001A
jmp  $040D
jmp  $0044
retr
call $0176
call $00EC
call $00E7
usr-1@wrk-1 asm48-0.0 $ tail amok.asm
dis  tcnti
movd a,p4
movd a,p4
movd a,p4
movd a,p4
movd a,p4
movd a,p4
movd a,p4
movd a,p4
movd a,p4
usr-1@wrk-1 asm48-0.0 $ ./asm48 amok.asm
Memory 0000 to 0FFF written to 'amok.hex'
usr-1@wrk-1 asm48-0.0 $ 

OK. Now we have amok.hex. This is not the format of the original binary, it needs to be converted to a bin format. A good program to do this is here. We put a copy of the source up here. To convert:

usr-1@wrk-1 asm48-0.0 $ hex2bin amok.hex
hex2bin v1.0.1, Copyright (C) 1999 Jacques Pelletier
Lowest address = 00000000
Highest address = 00000FFF
usr-1@wrk-1 asm48-0.0 $ 

Let's see if we match:

usr-1@wrk-1 asm48-0.0 $ diff amok.bin AMOKPD.BIN
usr-1@wrk-1 asm48-0.0 $ 

No difference. All is good. D52 gives a prettier, and more readable listing, so it may be helpful to understand your disassembly. For instance, if you use the -d option, you will get this:

usr-1@wrk-1 d52v33beta $ ./d48 -d amokpd
D48 8048/8041 Disassembler V 3.3
Copyright (C) 1996-2004 by J. L. Post
Released under the GNU General Public License
Initializing program spaces...
reading amokpd.bin
Highest location = 0fff
;
;  8048 Disassembly of amokpd.bin
;  04/11/04 5:56
;
org     0
;
X0000:  jmp     X02c3                           ; 0000 - 44 c3  DC
;
jmp     X0009                           ; 0002 - 04 09  ..
;
call    X040c                           ; 0004 - 94 0c  ..
jmp     X001a                           ; 0006 - 04 1a  ..
;
jmp     X040d                           ; 0008 - 84 0d  ..
.
.
.
X09c3   equ     9c3h
X0a0d   equ     0a0dh
X0b30   equ     0b30h
X0b3f   equ     0b3fh
X0b70   equ     0b70h
X0b87   equ     0b87h
X0bb9   equ     0bb9h
X0bea   equ     0beah
X0c0d   equ     0c0dh
X0dc5   equ     0dc5h
X0dea   equ     0deah
X0e70   equ     0e70h
X0e72   equ     0e72h
X0f0e   equ     0f0eh
X0f14   equ     0f14h
X0f19   equ     0f19h
X0f1e   equ     0f1eh
X0f20   equ     0f20h
X0f24   equ     0f24h
;
end
;





This article comes from Coprolite:
http://coprolite.com/

The URL for this story is:
http://coprolite.com/art33.html

Copyright 1997-2006 Coprolite.com. Read our Terms of Use.