You are on page 1of 18

Faculty of Engineering Computer Engineering Department Islamic University of Gaza

2011

Assembly Language Lab # 1


TASM & MASM Assemblers

Eng. Doaa Abu Jabal

Assembly Language Lab # 1


TASM & MASM Assemblers
Objective:
To be familiar with Assembly Language

Introduction:
Machine language can be made directly from java code using interpreter .

Java code

Interpreter

Machine Langauage

C ,C++ code is executed faster than Java code ,because they transferred to assembly language before machine language .

This is a C++ Program that print "Hello World" , we write the program on Visual Studio and Run the Program :

This is the result:

To convert C++ code to Assembly code we follow these steps: 1)

2)

3)

We will find the Assembly code on the project folder we save in ,named as ProjectName.cod

Assembly Language :
Assembly Language is a programming language that is very similar to machine language, but uses symbols instead of binary numbers. It is converted by the assembler (e.g. Tasm and Masm) into executable machine-language programs.

Running Hello Program on Tasm assembler :


1234click Start (All) Programs Run then write cmd and click OK. Go to directory C:\Tasm\Bin Type the command C:\Tasm\Bin\edit Hello.asm A blue screen will open.

5- write the following Hello program

Figure (2): Hello Program in Assembly language 6- Write C:\Tasm\Bin\tasm hello.asm to create the file hello.obj This file is the machine language for the program. 7- Write C:\Tasm\Bin\ tlink hello.obj to create the file hello.exe This file is executable program. 8- Finally, write C:\Tasm\Bin \hello.exe You will show the message hello, world on DOS screen

How to Debugging Assembly Language programs: 1. Using Tasm Turbo Debugger:


The Turbo Debugger is a program that allows you to single-step your program (that means run it line-by-line while you watch what happens). You can observe the registers, the memory dump, individual variables, flags, and the code as you trace through your program. Also it is used to debug errors that have to be made by logic reasons. After you write your program you can use assembly turbo debugger by follow the following:

C:\Tasm\Bin\td Hello

Number 1 2 3 4 5 6 7 Indicate to the menu bar of turbo debugger Indicate to the region contain Code pane Indicate to the region contain Register pane Indicate to the region contain Data pane Indicate to the region contain Flag pane Indicate to the region contain Stack pane

Description

Indicate to the instruction pointer (IP) it contains the offset address of the instruction will be execute. Indicate to Code register that have value of (42CC) and we get it from register pane. The offset address of each instruction This statement tell the assembler to put (@data) default offset address in AX and this value from gure equal to (42CD) indicate to the machine language of statement and from gure it is equal to (B8CD42) This column is the values of Registers.

8 9 10

11 12

Running Hello Program on MASM assembler : Installing MASM:


Double Click on the setup file located in \Tasm\MASM6.15\content

Assembling, Linking, Running a .asm File on MASM:


1-Make a folder for your assembly file 2-Extract the file MASM Files 3-Copy all the files in MASM Files to your Folder. 4-open the command window Start->Run 5-Write cmd then enter 6-Change Directory to your Folder using cd command

10

7-Write edit hello.asm the following screen will appear

8-Write your Assembly code the following is an example

9-Save your work then exit the editor 10-Type make16 yourfile then enter

Note:
You can open a notepad file and write your assembly file the save it as filename.asm

11

The following files will be created Yourfil.obj Yourfil.lst Yourfil.exe 11-Run your program using yourfile

Note:
Note if you use a 32 bit registers you will assemble and link using make32 instead of make16 command

12

How to Debugging Assembly Language programs: 2.Using Masm Turbo Debugger:


Make a folder for your assembly file, For Example "Assembly " ,Extract the file MASM Files then Copy all the files in MASM Files to your Folder ,open the command window Start->Run . Write cmd then enter ,Change Directory to your Folder using cd command.

After your program has been assembled and linked, you're ready to load its EXE file using CodeView. Open an MS-DOS command window, and type the following, pressing Enter after each line:

13

Here's what CodeView displays the first time you load the program. The highlight bar in the source window is automatically placed on your program's first executable instruction:

14

Begin Tracing the Program:


Press the F10 function key to begin tracing the program. Watch the highlight bar in the source window move downward, each time showing the next instruction about to be executed. Watch the registers change values. In the following example, we are about to execute line 19:

15

Keep pressing F10 message box says that the program has ended. This is not an error message.

16

You can now click on OK to restart the program, or press the Esc key to close the message box:

Restart the Program:


Any time while debugging, you can restart a program by selecting Restart from the Run menu. Try it now, and again trace the program using the F10 key. When you are finished debugging, select Exit from the File menu.

17

Lab work:
Write the previous code "Hello program", then Use Debugger to single step through this program using the (TRACE) command.

Home work
Make a report that explain the steps of setting up JCreator for assembling, linking, and debugging assembly language programs. We will do this by adding commands to its Tools menu. (JCreator HW) Folder will help you to do this configuration . Apply steps [1,2 and 5] only . After finish configuration , apply it on" Hello " program we write on this lab.

18

You might also like