Solo disponible en BuenasTareas
  • Páginas : 8 (1843 palabras )
  • Descarga(s) : 4
  • Publicado : 12 de mayo de 2010
Leer documento completo
Vista previa del texto
BBT 1203: Computer Organization
Assembly Language Programming
Tutorial 1


The objectives of this tutorial are to:
a) Introduce you to the use of the debugger.
b) Allow you to try out some common debug command


The MS-DOS debug program is a debugger available in any PC. It was initially designed for users to trace logical errors in executable files. Italso allows users to take an existing executable file and unassembled it, i.e. convert it to assembly language (sometimes called reverse engineering). A debugger also allows a user to write assembly languages directly, then covert them to machine language.

The debug program is simple and easy to use, but offers limited capabilities.

Introduction to Intel 8086 Assembly language

In thissection, you will be introduced to an assembly language program using a program that displays the traditional “Hello, world!” message on the screen. It contains the essential ingredients of an assembly language application.

The Hello World Program

title Hello World Program (hello.asm)

; This program displays “Hello, world!”
.model small
message db “Hello, world!”, 0dh, 0ah,’$’
main proc
mov ax, @data
mov ds, ax

mov ah, 9
mov dx, offset message

int 21h
mov ax, 4C00h
int 21h

main endp
end main
Here is a brief description of the important lines in theprogram:

• Line 1 contains the Title directive; all remaining characters on the line are treated as comments.
• Line 3 is a comment line, a line preceded by the ; .

Segments are the building blocks of programs: The code segment is where program instructions are stored; the data segment contains all variables, and the stack segment contains the program’s runtime stack. The stack is aspecial area of memory that the program uses when calling and returning from subroutines.

• The .model small directive indicates that the program uses a type of structure in which the program uses no more than 64K of memory for code, and 64K for data. The .stack directive sets aside 100h (256) bytes of stack space for the program. The .data directive marks the beginning of the data segmentwhere variables are stored.

In the declaration of message, the assembler allocates a block of memory to hold the string containing “Hello, world!,” along with two bytes containing a newline character sequence (0dh,0ah). The $ is a required string terminator character for the MS-DOS output subroutine being used.

• The .code directive marks the beginning of the code segment, where theexecutable instructions are located. The PROC directive declares the beginning of a procedure. In this program, we have a procedure called main.

• The first two statements in the main procedure copy the address of the data segment (@data) into the DS register.

• Next in the main procedure, we write a character string on the screen. This is done by calling an MS-DOS function thatdisplays a string whose address is in the DX register. The function number is placed in the AH register.

• The last two statements in the main procedure (mov ax, 4C00h / int 21h) halt the program and return control to the operating system.

• The statement main endp uses the ENDP directive. ENDP marks the end of the current procedure.

• The end of the program contains the enddirective, which is the last line to be assembled. The label main next to it identifies the location of the program entry point, that is, the point at which the CPU starts to execute the program’s instructions.

Note: We will not be writing our assembly own programs in this tutorial. Writing an assembly language program involves the following steps:

1. Enter the source assembly language program...
tracking img