Laboratory Work No 01 1 Introduction to Assembly Language Programming Introduction



Download 48.28 Kb.
Date07.08.2017
Size48.28 Kb.
#28106
Laboratory Work No 01

1 Introduction to Assembly Language Programming

Introduction:

This experiment introduces the student to assembly language programming. In order

to illustrate the basic concepts of assembly language programming a new environment

(TASM) is used as a tool to develop assembly programs.

The following tools will be used:

- Turbo-Assembler (TASM)

- Turbo-Linker(Tlink)

- Turbo-debugger(TD).



Objectives:

In this experiment you will learn:

a. TASM tool and [Turbo-Debugger].

1.1 Program Writing

The process of writing an assembly language program is facilitated through the use of

an Assembler. The Assembler allows the user to write alphanumeric instructions, or

mnemonics called instructions and then generate the machine code from the

Assembly Language instructions.

Assembly Language programming consists of the following steps:

a. Edit


b. Assemble

c. Link


d.Debug

e. Execute



1.1.1 Assembling

The assembler is used to convert the assembly language instructions into machine

code. It is used immediately after writing the Assembly Language program. The

assembler starts by checking the syntax, or validity of the structure, of each

instruction in the source file. If any errors are found, the assembler displays a report

on these errors along with a brief explanation of their nature. However, if the program

does not contain any errors, the assembler produces an object file that has the same

name as the original file but with the “obj” extension.


1.1.2 Linking

The linker is used to convert the object file to an executable file. The executable file is

the final set of machine code instructions that can directly be executed by the

microprocessor. It is different than the object file in the sense that it is self-contained

and re-locatable. An object file may represent one segment of a long program. This

segment can not operate by itself, and must be integrated with other object files

representing the rest of the program, in order to produce the final self-contained

executable file.

In addition to the executable file, the linker can also generate a special file called the

map file. This file contains information about the start, end, and the length of the

stack, code, and data segments. It also lists the entry point of the program.

1.1.3 Executing

The executable file contains the machine language code. It can be loaded in the RAM

and be executed by the microprocessor simply by typing, from the DOS prompt, the

name of the file followed by the Carriage Return Key (Enter Key). If the program

produces an output on the screen, or a sequence of control signals to control a piece of

hardware, the effect should be noticed almost instantly. However, if the program

manipulates data in memory, nothing would seem to have happened as a result of

executing the program.



1.2 Turbo-Assembler

The assembler being used in this lab is called TASM. TASM is an interactive

means for assembling linking and debugging assembly language programs.

Turbo- Assembler (TASM) is an integrated software package written by

Borland Corporation for professional software developers. It consists of an editor,

an assembler, a linker and a debugger .

The following table summarizes all the steps and commands used to edit, assemble

link and run a program using TASM.



Step Command Produces File Name

1 Editing Edit, use any simple editor Source File Filename.asm

2 Assembling Tasm Filename Object File Filename.obj

3 Linking Link Filename Executable File Filename.exe (or *.com)

4.Debugging Filename Executable File Filename.exe (or *.com)

5 Executing Filename Program output -


Figure A: First Program

ASSUME CS:code,DS:data

; kuku SEGMENT

; msg1 DB "Good afternoon!$"

; kuku ENDS

code SEGMENT

begin: MOV AX,data

MOV DS,AX

MOV AH,09h

MOV BX,offset msg

MOV DX,bx

INT 21h


MOV AX,0B800H

MOV ES,AX

MOV DI,80*2*24

MOV byte ptr ES:[DI],'G'

MOV byte ptr ES:2[DI],'O'

MOV byte ptr ES:4[DI],'O'

MOV byte ptr ES:6[DI],'D'

MOV byte ptr ES:8[DI],'!'

MOV AX,4C00h

INT 21h


code ENDS

data SEGMENT

msg DB '!!!!!!!!The program works!!!!!!$'

data ENDS

stk SEGMENT STACK

DB 256 DUP(?)

stk ENDS

END begin

After the program is saved, assemble it then link it. You should get and *.exe file in

your directory.

To assemble the program, at the DOS prompt type:



Figure 1.1: Screen Output after Assembly Phase

To link the program, at the DOS prompt type:



Figure 1.2: Screen Output after Link Phase

A p0.exe file is now created.



1.3. Using Turbo -Debugger

You can run your program by typing the following at the DOS prompt:


Use the following command to run code view: td p0.exe then press Enter.

You will get the following screen



Figure 1.3 TD Main Screen.

1.4 Pre Lab Work

Part I

1. Review the material related to introduction to assembly language programming

and data representation

2. Write the source code given in Figure A using the notepad or wordpad, then

assemble and link the program using the TASM and Tlink commands.

3. Write the attached programs and bring them to the lab. Use the DOS editor or the

Windows notepad. If you use a word processor, make sure that you chose the

option Save As Text while saving



Part II.

The MS DOS Debugger

The DOS “Debug” program is an example of simple debugger that comes with MS DOS. Hence, it is available on any PC. It was initially designed to give the user the capability to trace logical errors in executable files. It allows the user to take an existing executable file and unassembled it, i.e. convert it to assembly language. Also it allows the user to write assembly language instructions directly, and then convert them to machine language.

Below, are summarized the basic DOS Debugger’s commands:

A [assemble] It allows to transfer instructions, which are written in symbols into the machinery codes;

SYNTAX: A [address]



D [dump] It allows to show the contents of memory in the hexadecimal format;

SYNTAX: D [range]



E [enter] It allows to insert data into the memory, beginning from the given address;

SYNTAX: E [address]



G [go] It allows to start execution of the given program in the memory;

SYNTAX: G [address]



H [hex] It allows to perform hexadecimal arithmetic operations;

SYNTAX: H value1 value2



N [name] It allows to name the program;

SYNTAX: N [pathname] [argument list]



P [proceed] It allows to execute a group of instructions;

SYNTAX: P [address] [number]



Q [quit] It allows to quite a seance of DEBUG work;

SYNTAX: Q



R [register] It allows to show a contents of registers in the hexadecimal format;

SYNTAX: R [register]



T [trace] It allows to trace execution of one instruction;

SYNTAX: T [address] [value]



U [unassemble] It allows to transfer (disassemble) the machinery code into symbols.

SYNTAX: A [range]



Regulations of using DEBUG’s Instructions.

  • DEBUG doesn’t distinguish capital and small letters;

  • All data must be inserted in the hexadecimal format;

  • Blanks are used for parameters separation;

  • Segment and offset are assigned with help of “:”, i.e. in a form segment:offset

Lab Work

Part I

1- Assemble, Link and Debug program p0.

2- Use Turbo-Debugger to consider results of Assembler and Linker work.

3- Notice the values given by the assembler to the numbers you used in

your program. Draw a table and write each value with its

corresponding representation. What do you conclude?

4.- Dress a table and write the values assigned by the assembler to the

values you wrote in the editor. Write your comments (after ;).



Part II.

5- Practice the MS DOS debugger (compare it with Turbo-debugger of TASM).

Download 48.28 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page