assembly language lab # 1site.iugaza.edu.ps/mahindi/files/assembly-lab-1.pdf · assembly language...

19
Faculty of Engineering Computer Engineering Department Islamic University of Gaza Eng. Mohammad Elhindi 2011 Assembly Language Lab # 1 TASM & MASM Assemblers

Upload: tranthuy

Post on 06-Mar-2018

264 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

Faculty of Engineering Computer Engineering Department Islamic University of Gaza

Eng. Mohammad Elhindi

2011

Assembly Language Lab # 1 TASM & MASM Assemblers

Page 2: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

2

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 .

C ,C++ code is executed faster than Java code ,because they transferred to assembly

language before machine language .

Interpreter Java code Machine Langauage

Page 3: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

3

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

the Program :

This is the result:

Page 4: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

4

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

1)

2)

Page 5: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

5

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.

Page 6: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

6

Running Hello Program on Tasm assembler :

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

Page 7: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

7

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

Page 8: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

8

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

Page 9: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

9

Number Description

1 Indicate to the menu bar of turbo debugger

2 Indicate to the region contain Code pane

3 Indicate to the region contain Register pane

4 Indicate to the region contain Data pane

5 Indicate to the region contain Flag pane

6 Indicate to the region contain Stack pane

7 Indicate to the instruction pointer (IP) it contains the offset address of the instruction will be

execute.

8 Indicate to Code register that have value of (42CC) and we get it from register pane.

9 The offset address of each instruction

10 This statement tell the assembler to put (@data) default offset address in AX and this value from

figure equal to (42CD)

11 indicate to the machine language of statement and from figure it is equal to (B8CD42)

12 This column is the values of Registers.

Page 10: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

01

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

Page 11: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

00

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

Page 12: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

02

The following files will be created

Yourfil.obj

Yourfil.lst

Yourfil.exe

11-Run your program using yourfile

Page 13: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

03

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:

Page 14: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

04

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:

Page 15: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

05

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:

Page 16: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

06

Keep pressing F10 until you have executed the last instruction in the program ( INT 21h, line 26). You will

see a series of unfamiliar instructions in the source window after this. If you press F10 one more time, a

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

Page 17: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

07

Page 18: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

08

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.

Page 19: Assembly Language Lab # 1site.iugaza.edu.ps/mahindi/files/Assembly-lab-1.pdf · Assembly Language Lab # 1 TASM & MASM Assemblers ... How to Debugging Assembly Language programs: 2.Using

09

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.