DIsassembly listings - how to generate?

Building your first 6502-based project? We'll help you get started here.
Post Reply
manhattanmoments
Posts: 7
Joined: 27 Apr 2020

DIsassembly listings - how to generate?

Post by manhattanmoments »

Good morning,

how do I create these listings (whats the right terminology?) that seem to derive from disassembly processes and that contain (from left to right):

- line number,
- memory location (or programme counter?),
- hex code,
- assembly language programme,
- comments?

(see example image attached)

I want to create something similar, not primarily for debugging but for the sake of the aesthetics of these listings.
Is there a disassembler software that creates this output out of a binary file? I would need this for MAC OS.
I'm rather new in all this. I started to learn programming in assembly with AVR Assembly language. Now I built an 8-bit system for my own based on the 65C02 following Ben Eaters videos.
So far I can create hexdump listings with Hexcode (left side) and ASCII equivalents (right side), using the simple "hexdump -C [filename.rom]" command in command line.
But how can I create more complex listings like I described above? Is this hand made or the output of a programme?
(I already checked all the disassemblers listed under "Assemblers, Disassemblers, and Optimizers" in Development Tools section of 6502.org)

Thanks for any advice and help!
Attachments
Disassembly_listings.png
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: DIsassembly listings - how to generate?

Post by BigEd »

Welcome!

I'd call that kind of thing a listing file - it's what an assembler will produce, or can produce, when it assembles the source. It's the source which contains the comments.

Where a disassembler comes in is when you don't have the source (and you can't get it from someone else) - you take a binary, a disassembler, and a certain amount of care and attention, and you construct a source file which, when assembled, creates the same binary as you started with.

You still need to add the comments, which means understanding the intent and the structure of the code - this understanding will, in part, come from the process of coaxing the disassembler into producing a nice result. The best disassemblers will take as inputs both the binary file and some annotations and metadata: these are the bits which come from your growing understanding of the code.
manhattanmoments
Posts: 7
Joined: 27 Apr 2020

Re: DIsassembly listings - how to generate?

Post by manhattanmoments »

Thank you, BigEd, that was helpful!
So, I assume that the assembler is creating some kind of these listings?
I use vasm for assembling my programs written assembly. Any help on how getting these listings out of there or any other assembler that works in command line on a Mac?
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: DIsassembly listings - how to generate?

Post by BigEd »

I would hope any command line assembler would oblige. Here's vasm's help:
Quote:
‘-L <listfile>’
Enables generation of a listing file and directs the output into the file <listfile>.

‘-Ll<lines>’
Set the number of lines per listing file page to <lines>.

‘-Lnf’
Do not emit any form feed code into the listing file, for starting a new page.

‘-Lns’
Do not include symbols in the listing file.
manhattanmoments
Posts: 7
Joined: 27 Apr 2020

Re: DIsassembly listings - how to generate?

Post by manhattanmoments »

Thanks a lot! The -L command works! The others give me an error message, think I need to play around a bit.
The format of the listing (see attached image) is fixed I assume, isn't it? So, I can't just put the assembly code to the right hand side of the hex code, correct?
Attachments
listing.png
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: DIsassembly listings - how to generate?

Post by GARTHWILSON »

The assemblers I've used put it like your first picture, where the addresses and hex code are put to the left of your own source code. The also have options to show the macro expansions or not. Sometimes there's an alphabetized list at the end of all the labels and how many times they're referenced and maybe a list of line numbers that reference each one.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
manhattanmoments
Posts: 7
Joined: 27 Apr 2020

Re: DIsassembly listings - how to generate?

Post by manhattanmoments »

Thanks, GARTHWILSON! What assemblers did you use that gave you this kind of listings?

EDITED: Ok, saw them now on your page.
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

Re: DIsassembly listings - how to generate?

Post by BitWise »

If you have a Java 1.8 run time on your system then my portable assembler tools would produce a more traditional listing.

My tools are written in Java and work on Windows and Linux (Intel & ARM). They should work on OS/X.

There is a demo here: https://github.com/andrew-jacobs/trains
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
dwight
Posts: 213
Joined: 08 Jun 2004

Re: DIsassembly listings - how to generate?

Post by dwight »

My disassemblers first find the first block of code to follow. It then has a blank text file with spaces with all the addresses to be covered. It puts instruction on the lines in place of the spaces. It then makes a list of every branch, subroutine call or jump address. It makes passes through the data, stopping at every jump it goes back to the list of branch, subroutine or jump address. If it has disassemble that address it goes to the next address in the table and disassembles that when it runs out of addresses I look back at the holes and determine if they look like data or instructions. If instructions, they are disassembled if not they are put into the file as data blocks. I look at the data blocks later to see if they look like strings of text if so I convert them to text. Once I made all the various passes through the data and disassembled all the destinations.
I also make comments of counts that each of the entry points is used from the table. If it is only used locally, it is usually some IF or BEGIN type code. If it is used many times from different parts of the code, it is an important routine. I start to try to figure out what the code does and make comments.
One need to be familiar with a particular processors code to begin to understand what is happening. In 6502 Y is used with some zero page for indirect references.
It is not easy. There will be many times when you've looked at one piece of code over and over and it finally makes sense.
Piece by piece it ties together. You also need to know the ports and what other ROM may be there.
Anyway, I do not just start at one end and try to threat everything as code. It will get misaligned every time you hit a data block. It will require many passes to clean up. I let my branch,call and jump address tables determine where to disassemble and were to leave possible data blocks. This method gets almost all of the code right with few exceptions. One only needs to look a the remaining part to decide if it is data values, indirect address, strings or other data types ( like graphic data ).
Dwight
User avatar
Mike Naberezny
Site Admin
Posts: 293
Joined: 30 Aug 2002
Location: Northern California
Contact:

Re: DIsassembly listings - how to generate?

Post by Mike Naberezny »

manhattanmoments wrote:
(see example image attached)
That looks familiar! See page 21:
http://6502.org/documents/books/keith_s ... _ksmon.pdf

Sometimes I scan these documents and wonder if people will read them. I'm glad to see that sometimes they do.

Here are more listings from the same set:
http://6502.org/documents/books/keith_sproul/
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: DIsassembly listings - how to generate?

Post by GARTHWILSON »

manhattanmoments wrote:
Thanks, GARTHWILSON! What assemblers did you use that gave you this kind of listings?

EDITED: Ok, saw them now on your page.

Maybe I should answer it anyway. The commercial assemblers I've used for the 65's are the 2500AD assembler (1986-1993), and Cross-32 (1993 to present), and for the PIC microcontrollers, MPASM from Microchip. My workbench computer has a Forth kernel in EPROM, including a simple assembler I wrote for it; but it does not generate a .lst file. (Being Forth however, it automatically has macro capability, and I can also put many assembly-language instructions on a single line.)
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Post Reply