Post on 27-Nov-2014
Faculty of EngineeringComputer Engineering Department
Islamic University of Gaza
Eng. Doaa Abu Jabal
2011
Assembly Language Lab # 1TASM & MASM Assemblers
2
Assembly Language Lab # 1TASM & 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 assemblylanguage before machine language .
InterpreterJava code Machine Langauage
3
This is a C++ Program that print "Hello World" , we write the program on Visual Studio and Runthe Program :
This is the result:
4
To convert C++ code to Assembly code we follow these steps:
1)
2)
5
3)
We will find the Assembly code on the project folder we save in ,named asProjectName.cod
Assembly Language :
Assembly Language is a programming language that is very similar to machine language, butuses symbols instead of binary numbers. It is converted by the assembler (e.g. Tasm and Masm)into executable machine-language programs.
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\Bin3- Type the command C:\Tasm\Bin\edit Hello.asm4- A blue screen will open.
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 languagefor 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
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 languagefor 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
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 languagefor 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
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 itline-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
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 itline-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
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 itline-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
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 beexecute.
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 fromfigure 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.
10
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
11
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
12
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
13
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 allthe 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 usingCodeView. Open an MS-DOS command window, and type the following, pressing Enter aftereach line:
14
Here's what CodeView displays the first time you load the program. The highlight bar in the sourcewindow is automatically placed on your program's first executable instruction:
15
Begin Tracing the Program:
Press the F10 function key to begin tracing the program. Watch the highlight bar in the sourcewindow move downward, each time showing the next instruction about to be executed. Watchthe registers change values. In the following example, we are about to execute line 19:
16
Keep pressing F10
message box says that the program has ended. This is not an error message.
17
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.
18
Lab work:
Write the previous code "Hello program", then Use Debugger to single step through this program usingthe (TRACE) command.
Home work
Make a report that explain the steps of setting up JCreator for assembling, linking, and debuggingassembly 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.