Department of Electrical and Computer Engineering
University
of Wisconsin-Madison

ECE 353: INTRODUCTION TO MICROPROCESSOR SYSTEMS
Spring 2005

Turbo Assembler/Debugger Tutorial

TABLE OF CONTENTS

·  1 Introduction

·  2 Example Source Code

·  3 Edit Source Code Files

·  4 Assembling and Linking Source Code

·  5 Turbo Debugger

·  6 Multiple Source File Programs

·  7 Appendix

·  7.1 Key Turbo Debugger Commands

·  7.2 Using the Mouse In Turbo Debugger 

·  7.3 Batch File


1 Introduction

This semester we will use the Borland Turbo Assembler, Turbo Linker, and Turbo Debugger available at CAE on the Novell (Windows) PC network. You are to download the following program from the course web page, assemble it, debug it, fix any errors which may cause the program to not work, and get it running.

2 Example Source Code

The following source code is provided for this tutorial as a text file hello.asm linked on the course web page.  The source code has two errors, one on each of the two lines indicated in bold type.  Do not fix the errors until after you try to assemble the program and see the reported errors.  This will help to give you some idea of the type and extent of information that the assembler will give you when it detects an error.

; Filename: hello.asm
; Author: ECE 353 Staff
; Description: 'Hello, World' source for TASM tutorial
;
        .186                            ; generate code for 80C186/80188
 
        assume cs:code, ds:data         ; establish addressability
;
data    segment public                  ; begin data segment
hello   db 'Hello, World',13,10,'$'     ; defines a string at label "hello"
data    ends                            ; end of data segment
 
code    segment public                  ; begin code segment
start:
        move ax, data                   ; configure data segment as assumed
        mov  ds, ax 
;
        mov  ah, 9                      ; specifies which DOS function to call
        mov  dx, offset hollo           ; puts the address of the string in DX
        int  21h                        ; invoke DOS interrupt
;
        mov  ah, 4Ch                    ; specifies the program exit function
        int  21h                        ; invoke DOS interrupt
;
code    ends                            ; end of code segment
;
end     start                           ; set code entry point to 'start'
;

The example code is available as a text file hello.asm on the course web page.  The two errors in the program are; the instruction move on the first bold line should be mov, and the label hollo on the second bold line should be hello.

3 Editing Source Code Files

You can use any Windows text editor (i.e. Notepad, WordPad) that saves the file as plain ASCII text, although you may find that the Microsoft Visual C++ editor is more convenient since it supports auto-indenting. If you want to edit within a DOS window, you can use either of the DOS text editors "qedit" or "edit".  Always save your source code with the extension 'asm'. 

4 Assembling and Linking Source Code

Before you can use the Borland tools you must run a setup program. From the CAE Windows machines press Start->CAE Application->Programming->Borland Turbo Assembler v5.0. A command window will launch; and at the top you will see the message "This command window is now ready for using TASM.". Now you are ready to assemble your .asm file. To do so, type the command:

tasm /l /zi filename 

The /l will create a listing file (*.lst) and the /zi will cause the assembler to insert debugging information in the object file. If you type tasm by itself, you will get a screen full of command line options.

Next, type:

tlink /v filename ( without extension)  

The /v causes the linker to put debugging information in the executable. TLINK will produce a file called filename.exe, which is a DOS executable file. To simplify things, it is best to use a batch file to automate these commands (see 7.3 below).  TLINK will always give a warning message "Warning: No Stack" since we will not define our stack using the TASM stack directive.  This warning is not a problem.

5 Turbo Debugger

To start the debugger, type: td filename. At the bottom of the screen you will see the functions tied to the function keys. At the top, there is a menu bar which can be accessed with the mouse (in Windows XP or if the DOS window is full-screen for other versions of Windows) or with the key strokes. Type ALT-V, and then type C, to get a view of the CPU state (the V and C are just lower case). The ALT key takes you to the menu bar on top of the screen. You are then able to select options by pressing the arrow keys or enter the highlighted character. This works for menu windows as well as all other windows. (The mouse only works for Windows XP or for other versions of Windows if the DOS window is maximized, see 7.2 below) In the CPU window, you will see your program code, the CPU registers, the flags, the stack, and the contents of memory where your program is located. You can step through the program using the F7 key. Notice that when the content of a register changes, the register is highlighted. At the end of the program go to the menu bar and select Window->User screen to see what happened. Hit Esc to return to the debugger screen. Now you can try entering the sample example and start getting used to the debugger.

To view Registers --- Hit <Alt>-V, then R to view the registers. Then hit <Ctrl>-F5 or use the mouse if possible to move it. If using the keyboard, hit <Enter> after you get it where you want it.

The above sample program is a simple shell that can be used to write DOS programs. In the data segment, variables can be defined, both initialized with specific values and uninitialized. The rest of the program and procedures will be written in the code segment. Writing programs for embedded systems will have a slightly different form, to be introduced later.

6 Multiple Source File Programs

For most programs, having all the source code in a single file is impractical.  So we use multiple source code files, each of which is assembled independently to generate and object code file.  Then the linker is used to join all the of the object code files into a single executable, resolving the references between the source files and combining public segments with the same name into a single segment.

From the course web page, download main.asm, strchr.asm, and t.bat.  The batch file will assemble both source code files, then link them into the executable file demo.exe.  Using Turbo Debugger, step through the program, using Step Into to follow the procedure call.  Becoming familiar with the debugger capabilities will be very helpful as you write and debug software during the course of the semester.

7 Appendix 

7.1 Key Turbo Debugger Commands

  1. F7 – Step through each line of codes 
  2. F8 – Step into each procedure call (if exists) 
  3. Alt-V, C – Shows CPU contents 
  4. Alt-V, R – Show registers and flags contents only
  5. Ctrl-F7 – Add a variable watch
  6. Run -> Animate – Watch the code execute slowly to follow flow

7.2 Using the Mouse in Turbo Debugger

Press Alt–ENTER on the DOS window to maximize the DOS window.  With the DOS window maximized you can use the mouse to navigate menus and resize internal windows. Press Alt–ENTER again to restore the DOS window. 

7.3 Batch File

A sample batch file is shown below to simplify the assemble/link process for a single source file program.

tasm /l/zi %1
tlink /v %1

Save this in a file t.bat in your working directory. To build your executable, you can then simply simply enter
    t <filename>.