instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/assembl_15/lectur/01_ass/00i_lab.… · web...

8
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

Upload: duongnga

Post on 28-May-2019

215 views

Category:

Documents


0 download

TRANSCRIPT

Laboratory Work No 011 Introduction to Assembly Language ProgrammingIntroduction:This experiment introduces the student to assembly language programming. In orderto 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 WritingThe process of writing an assembly language program is facilitated through the use ofan Assembler. The Assembler allows the user to write alphanumeric instructions, ormnemonics called instructions and then generate the machine code from theAssembly Language instructions.Assembly Language programming consists of the following steps:a. Editb. Assemblec. Linkd.Debuge. Execute1.1.1 AssemblingThe assembler is used to convert the assembly language instructions into machinecode. It is used immediately after writing the Assembly Language program. Theassembler starts by checking the syntax, or validity of the structure, of eachinstruction in the source file. If any errors are found, the assembler displays a reporton these errors along with a brief explanation of their nature. However, if the programdoes not contain any errors, the assembler produces an object file that has the samename as the original file but with the “obj” extension.

1.1.2 LinkingThe linker is used to convert the object file to an executable file. The executable file isthe final set of machine code instructions that can directly be executed by themicroprocessor. It is different than the object file in the sense that it is self-containedand re-locatable. An object file may represent one segment of a long program. Thissegment can not operate by itself, and must be integrated with other object filesrepresenting the rest of the program, in order to produce the final self-containedexecutable file.In addition to the executable file, the linker can also generate a special file called themap file. This file contains information about the start, end, and the length of thestack, code, and data segments. It also lists the entry point of the program.1.1.3 ExecutingThe 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, thename of the file followed by the Carriage Return Key (Enter Key). If the programproduces an output on the screen, or a sequence of control signals to control a piece ofhardware, the effect should be noticed almost instantly. However, if the programmanipulates data in memory, nothing would seem to have happened as a result ofexecuting the program.1.2 Turbo-AssemblerThe assembler being used in this lab is called TASM. TASM is an interactivemeans for assembling linking and debugging assembly language programs.Turbo- Assembler (TASM) is an integrated software package written byBorland 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, assemblelink and run a program using TASM.Step Command Produces File Name1 Editing Edit, use any simple editor Source File Filename.asm2 Assembling Tasm Filename Object File Filename.obj3 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 ProgramASSUME CS:code,DS:data ; kuku SEGMENT ; msg1 DB "Good afternoon!$" ; kuku ENDScode 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 beginAfter the program is saved, assemble it then link it. You should get and *.exe file inyour 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 PhaseA p0.exe file is now created. 1.3. Using Turbo -DebuggerYou 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 WorkPart I1. Review the material related to introduction to assembly language programmingand data representation2. Write the source code given in Figure A using the notepad or wordpad, thenassemble 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 theWindows notepad. If you use a word processor, make sure that you chose theoption 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:offsetLab WorkPart I1- 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 inyour program. Draw a table and write each value with itscorresponding representation. What do you conclude?4.- Dress a table and write the values assigned by the assembler to thevalues you wrote in the editor. Write your comments (after ;).Part II.5- Practice the MS DOS debugger (compare it with Turbo-debugger of TASM).