computer organization
c m s c 311  
s p r i n g   2 0 0 3  

Project #1

(Partial) Disassembler Specs

Goals

These are the lessons to learn from this part of the project: Some of the skills used in the hex dump utility also apply to the this part of the project. This should make this part of the project somewhat easier.

Clarifications and Such

If there are errors and ambiguities, please send email to clin@umd5.umd.edu. I will be checking this description during weekend starting Feb 22., possibly adding corrections if needed.

Background

An assembler is a program that translates programs written in assembly language into machine code. Machine code is essentially the binary equivalent of the assembly language. As assembler behaves functionally like a compiler. That is, its purpose is to convert from one language to another.

However, there's almost a 1-1 correspondence between assembly language programs (at least, the text portion). That means, there's not that much translation to do to get from assembly lanugage to machine code (it's tedious, but not particularly hard).

Assembly language was developed when the first programmers, who wrote their code in machine code, found it too error-prone and slow. So, they wrote "human-readable" code, and then wrote a program (i.e., the assembler) to convert it to machine code.

A disassembler works in reverse. It takes machine code and produces the equivalent assembly language program. At times, the machine code may not have all the information that the assembly language program contains.

In particular, comments are typically removed, and labels may also be removed. We'll explain what label are in the next section.

Structure of MIPS program

A typical assembly language program consists of two parts: the data segment and the text segment. Think of the data segment as a kind of global variable declaration and initialization. This part of the program is not always standardized, and varies from assembler to assembler.

The text segment is the "code" portion, where you write out the instructions to perform a task.

The basic structure of a program looks like:

  .data  # This is a comment
# DATA STUFF GOES HERE

  .text
# PROGRAM GOES HERE
Comments are shown with a #, which behaves like // in C++. Comments are ignored by the assembler.

Assembly lanugage is very line-oriented. In C, each statement usually ends in a semicolon. In assembly language, most statements must appear on a single line.

The keyword .data begins the data segment, and the keyword .text begins the text segment. Each appears in its own line.

All you have to do is write the disassembler for the data segment. I'll be making up the format for the data segment. It will resemble the format given in SPIM (the MIPS simulator, described at the end of your book), but it's not exactly the same. The data segment tends to vary from assembler to assembler.

The specs for the data segment are shown in the next section.

Specifications

Here's the overall picture. I'm describing the data segment of an assembly language program. Then, I'll describe how this segment is encoded to a binary file. You will use the input file, and

I'm doing to define a term called a declaration.

A declaration is going to consist of:

Here are some examples:

num1: int 3
num2: int -3
num3:
  int
 4
arr1: int [5] 3 3 3 -2 -2
arr2: int [5] 3*1 -2*4
arr3: unsigned [5] 3
arr4: unsigned [5] 4*2
b1: byte 0x41
b2: byte 0X41
barr: byte [3] 0x11 0x11 0x11
str: ascii "Hi there"
str2: asciiz "Hi there\n"
The description above may seem unusual. After all, it describes an assembler. You're writing a disassember.

Still, it's useful to have this information, because you need to know the syntax for a program because that's the output of your program.

Now to get to storing this information. The binary file contains the following:

Syntax of declarations

Each declaration consists of a label, a type, possibly followed by the size of an array (if it's an array), followed by a list of representations. The number of representations will equal the size of the array.

Let's be more specific. Each declaration will have the following information in the binary file. The list of

Each declaration (i.e., each label and associated information) will have the information above, concatenated one right after another. This is why it's important to know the number of declarations.

Also, note that we store the labels in the file itself. In general, this may not be necessary. Labels often refer to addresses, and therefore once the address is computed by the assembler, the labels are sometimes not necessary.

Typically, labels for function names are needed, especially for linking. But other labels may not be needed.

However, in our project, we record all the label information in the output.

Coding Strategy

I would consider creating a structure or class that stores the information of each declaration (i.e., the label, the type, and the information). Then store this in, say, a vector or an array of such structures.

This information can be used later on, if necessary.

Sometimes it's a good idea to have a structure/class to store the information, rather than processing it on the fly, and throwing away the information once it's done.

There is clearly a tradeoff. If you process the information as you read it, then you need less space to store the informmation. On the other hand, storing the information allows you to use the information later on.

Outputting Information

Assume the name of the executable is: disassem.

You should allow for two command line switches:

You should expect the switches to appear in any order. You may assume input file exists and output file do not.

If there is no command-line argument, write the data portion of the file to standard output.

This is what you should output:

What's a Binary File?

Technically, all files are binary files. They contain bytes of information. However, usually there's a distinction made between text files, which are human readable, and binary files which are often NOT human readable.

Thus, foo.cpp is considered a text or ASCII file, because you enter text in a text editor (in the future, perhaps they will be Unicode files). foo.o is considered a binary file because it's not human-readable (for the most part).

Binary files are often used because they represent information more compactly, and also because they are not human readable (many software products that you may purchase do not provide source code, but only provide binaries).

Since ASCII files are still, technically, binary files, you can run the hex dump utility on them and read them.

Extra Credit

Here are a list of extra credit options. This part of the project is worth 100 points (note: total project points may not add up to 100, but will be scaled to 100 points later on).


See the class syllabus for policies concerning email
Last Modified: Fri Feb 14 09:13:38 EST 2003
left up down right home

Web Accessibility