+ All Categories
Home > Documents > Lab #1 Lab Policy and Tools - Islamic University of...

Lab #1 Lab Policy and Tools - Islamic University of...

Date post: 06-Aug-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
21
Lab #1 Lab Policy and Tools Eng. Ruba A. Salamah Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB
Transcript
Page 1: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

Lab #1

Lab Policy and Tools

Eng. Ruba A. Salamah

Islamic University – Gaza

Engineering Faculty Department of Computer Engineering

ECOM 2125: Assembly Language LAB

Page 2: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

Instructor: Eng. Ruba A. Salamah Office L506

Webpage http://site.iugaza.edu.ps/rsalamah/

Email [email protected]

Lab Policy

Attendance is mandatory.

Quizzes will be given after first 5 minutes. You should be early to the lab session.

Reports should be ready on my table in the lab before I come to the lab.

Provide a cover page including your name in English, your ID, your class number, the report title and number, and the submission date.

Copiers and late submissions are penalized. A result of zero will be graded.

You should check my web page and your email.

Every lab has two types of exercises:

1. Lab Exercise: do in the lab.

2. Homework Exercise: you will solve the questions after the lab and deliver it in the following lab.

Grading Policy Lab Quizzes 30 Attendance & Lab work 20 Lab Reports 10 Final Exam 40

Page 3: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

2 Assembly Language LAB

Introduction

Machine language (computer's native language) is a system of impartible instructions

executed directly by a computer's central processing unit (CPU). Instructions consist of binary code: 1s and 0s.

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. Assembly language is machine-dependent; an assembly program can only be executed on a particular machine.

Page 4: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

3 Assembly Language LAB

1. Introduction to Assembly Language Tools

Software tools are used for editing, assembling, linking, and debugging assembly language programming. You will need an assembler, a linker, a debugger, and an editor. These tools are briefly explained below.

1.1 Assembler An assembler is a program that converts source-code programs written in assembly language into object files in machine language. Popular assemblers have emerged over the years for the Intel family of processors. These include MASM (Macro Assembler from Microsoft), TASM (Turbo Assembler from Borland), NASM (Netwide Assembler for both Windows and Linux), and GNU assembler distributed by the free software foundation. We will use MASM 6.15.

1.2 Linker A linker is a program that combines your program's object file created by the assembler with other object files and link libraries, and produces a single executable program. You need a linker utility to produce executable files. Two linkers: LINK.EXE and LINK32.EXE are provided with the MASM 6.15 distribution to link 16-bit real-address mode and 32-bit protected-address mode programs respectively. We will also use a link library for basic input-output. Two versions of the link library exist that were originally developed by Kip Irvine. The 32-bit version is called Irvine32.lib and works in Win32 console mode under MS-Windows, while the 16-bit version is called Irvine16.lib and works under MS-DOS.

1.3 Debugger A debugger is a program that allows you to trace the execution of a program and examine the content of registers and memory. For 16-bit programs, MASM supplies a 16-bit debugger named CodeView. CodeView can be used to debug only 16-bit programs and is already provided with the MASM 6.15 distribution. For 32-bit protected-mode programs, you need a 32-bit debugger.

1.4 Editor You need a text editor to create assembly language source files. You can use NotePad, or any other editor that produces plain ASCII text files. You can also use the ConTEXT editor. ConTEXT is a powerful editor that can be easily customized and can be used as a programming environment to program in assembly language. It has built-in syntax highlighting feature.

Page 5: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

4 Assembly Language LAB

2. Lab Work: Installing MASM 6.15

Step 1: Download MASM615.exe, a self-extract executable file, from https://www.dropbox.com/s/aujk44ym14jfi74/MASM615.exe. Step 2: Double click on MASM615.exe to extract the files. Specify the installation directory. We recommend using C:\Program Files\ as the destination directory, but any other directory will do.

Step 3: Define an environment variable MASMDIR for the installation directory. Under Control Panel, double-click on System to obtain the System Properties dialog box. Under System Properties, click on the Advanced tab. Click on the Environment Variables button.

Page 6: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

5 Assembly Language LAB

Under Environment Variables, Click on the New button to add a New System Variable. Add MASMDIR as the variable name and the C:\Program Files\MASM615 as the variable value and press OK. The MASMDIR variable and its value should now appear under System variables. If a different installation directory is chosen for MASM 6.15 then specify it here.

Page 7: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

6 Assembly Language LAB

Step 4: Edit the Path system variable by inserting %MASMDIR%; (don't forget the semicolon) at the beginning of the variable value.

Page 8: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

7 Assembly Language LAB

Step 5: Define a new system variable called INCLUDE with value %MASMDIR%\INCLUDE as show below and press OK. This variable specifies the directory that contains the include (.inc) files.

Page 9: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

8 Assembly Language LAB

Step 6: Define a new system variable called LIB with value %MASMDIR%\LIB as show below and press OK. This variable specifies the directory that contains the link library (.lib) files.

Step 7: Check the environment variables. Open a Command Prompt and type:

- SET MASMDIR - SET INCLUDE

- SET LIB - PATH

These commands should display the MASMDIR, INCLUDE, LIB, and PATH environment variables as shown below. If the installation steps are done properly, you can start using the MASM commands.

Or, instead of the previous steps (step 3 to step 6) you can make a folder for your assembly file and copy all the files in MASM165 files to your folder. But in this situation you must put every assembly file you create in this folder.

3. Displaying a Welcome Statement

The first assembly-language program that you will assemble, link, and run is welcome.asm. This program displays a welcome statement on the screen and terminates. You can open this program using any text editor. We will not go over the details of this program in this first lab. You will understand these details in future labs.

Page 10: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

9 Assembly Language LAB

TITLE Displaying a Welcoming Message (welcome.asm)

.686

.MODEL flat, stdcall

.STACK

INCLUDE Irvine32.inc

.data

CR EQU 0Dh ; carriage return

LF EQU 0Ah ; line feed

welcome BYTE "Welcome to Assembly Language Lab",CR,LF

BYTE "Enjoy this lab",CR,LF,0

.code

main PROC

; Clear the screen

call Clrscr ; Call procedure Clrscr

; Write a null-terminated string to standard output

lea edx, welcome ; load effective address of welcome into edx

call WriteString ; write string whose address is in edx

exit

main ENDP

END main

3.1 Lab Work: Assembling and Linking a Program Open a Command Prompt and type the following command. This command will assemble and link the welcome.asm program. make32 welcome

Page 11: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

10 Assembly Language LAB

3.2 Lab Work: Running a Program The make32 command will generate is the welcome.exe executable file. You can now run the welcome.exe program by simply typing welcome at the command prompt.

4. Lab Work: Installing the 32-bit Windows Debugger

Step 1: Download the 32-bit debugger installer from https://www.dropbox.com/s/kyq8v7e4ym9r7oe/dbg_x86_6.5.3.7.exe. Step 2: Double click on the installer executable file and follow the on-screen instructions. Step 3: Edit the Path system variable by appending the installation directory of the windows debugger C:\Program Files\Debugging Tools for Windows\ at the end of the Path value. Don't forget to use the semicolon as a separator between various directories in the Path system variable.

Step 4: Open a Command Prompt and type: path. This command should display the value of the path variable. Make sure to have the installation directory of the debugger C:\Program Files\Debugging Tools for Windows\ as part of the PATH variable.

Page 12: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

11 Assembly Language LAB

5. Lab Work: Using the 32-bit Windows Debugger

We will use the Windows debugger extensively throughout this semester to trace and debug programs. At the Command Prompt, type: windbg –QY –G welcome.exe to run the Windows Debugger.

Open the source file welcome.asm from the File menu (or click on the button). Place the

cursor at the beginning of the main procedure and press F7 (or click the button) to start

the execution of the main procedure. Press F10 (or click the button) to step through the execution of the main procedure. Observe the console output as you step through the execution.

Page 13: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

12 Assembly Language LAB

6. Installing the ConTEXT Editor

Step 1: Download the ConTEXT editor installer from https://www.dropbox.com/s/750ie9mswc3ohkj/ConTEXTsetup.exe. Step 2: Run ConTEXTsetup.exe program. This will install the ConTEXT editor.

7. Customizing ConTEXT

Step 1: Download the MASM syntax highlighter from https://www.dropbox.com/s/amulirm5xawzld0/MASM.chl. Step 2: Copy the MASM highlighter to the C:\Program Files\ConTEXT\Highlighters directory, assuming that you have ConTEXT in C:\Program Files\ConTEXT directory. Step 3: Start the ConTEXT editor. Select Environment Options from the Options menu. You can customize many options of ConTEXT. Click on Editor and select Line numbers to display the line numbers in the editor. Select also the default Highlighter as MASM. Other options can be customized as shown.

Page 14: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

13 Assembly Language LAB

Step 4: Now click on Execute Keys to define new execution keys for assembly language programs. Click on the Add button. This will open the Extension edit dialog box as shown below. Enter asm as the extension for assembly language programs and press OK. You can now define four execution keys (F9, F10, F11, and F12) to execute various commands. We will define these keys to assemble, link, and debug assembly language programs, as described below.

Page 15: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

14 Assembly Language LAB

Step 5: Define the F9 key as shown below. This will execute the make32.bat batch file under the "C:\Program Files\MASM615\" directory, where MASM has been installed. Enter C:\Program Files\MASM615\make32.bat under the Execute field. This batch file will Assemble and Link 32-bit Programs. Write this information in the Hint field and fill-in and select the fields as shown below.

Page 16: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

15 Assembly Language LAB

Step 6: Define the F10 key as shown below to use the 32-bit Windows Debugger. Enter C:\Program Files\Debugging Tools for Windows\windbg.exe under the Execute field. Enter also -QY -G %F.exe under Parameters.

Page 17: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

16 Assembly Language LAB

Step 7: Define the F11 key as shown below. This will execute the make16.bat batch file under the C:\Program Files\MASM615\ directory, where MASM has been installed. Enter C:\Program Files\MASM615\make16.bat under the Execute field. This batch file will Assemble and Link 16-bit Programs. Write this information in the Hint field and fill-in and select the fields as shown below.

Page 18: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

17 Assembly Language LAB

Step 8: Define the F12 key as shown below. This key will be used to start the 16-bit CodeView Debugger. Enter C:\Program Files\MASM615\CV.exe under the Execute field. Enter also /50 %F under Parameters as shown. Now press OK to apply the changes and start using the newly defined execution keys.

8. Using the ConTEXT Editor

Open program welcome.asm file with ConTEXT. You can make this association by clicking on the right mouse-button and select Open With ... and selecting ConTEXT. Also select the checkbox: Always use the selected program to open this kind of file to make this association permanent. This is how an assembly language program looks like in ConTEXT. Make sure to select the MASM highlighter. You may change the colors if you don't like them, by selecting the Colors tab under Environment Options.

Page 19: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

18 Assembly Language LAB

To associate the MASM highlighter with all assembly-language source files, go to the Tools menu and choose Set Highlighter ►Customize Type … Select the MASM highlighter and click Edit to specify the extensions for this highlighter. Enter the extensions asm, inc and press OK as shown below:

Page 20: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

19 Assembly Language LAB

The MASM highlighter is now associated with assembly-language source files with (.asm) extension, and include files with (.inc) extension. Press OK and you are done.

From the Tools menu select Assemble and Link 32-bit Program. Alternatively, you may press F9. This command should work if ConTEXT was configured properly. This will execute the make32.bat batch command that assemble and link the welcome.asm program. You can also start the 32-bit Windows Debugger from the Tools menu, or by pressing the F10 key.

Page 21: Lab #1 Lab Policy and Tools - Islamic University of Gazasite.iugaza.edu.ps/rsalamah/files/2015/02/Lab1.pdf · 2015-02-15 · 2 Assembly Language LAB Introduction Machine language

20 Assembly Language LAB

Homework Exercise

Modify the welcome.asm program to display a message of your choice.

Best Wishes


Recommended