Introduction to Assly Language ProgrammingCCSE.doc

上传人:laozhun 文档编号:2884179 上传时间:2023-03-01 格式:DOC 页数:9 大小:211.50KB
返回 下载 相关 举报
Introduction to Assly Language ProgrammingCCSE.doc_第1页
第1页 / 共9页
Introduction to Assly Language ProgrammingCCSE.doc_第2页
第2页 / 共9页
Introduction to Assly Language ProgrammingCCSE.doc_第3页
第3页 / 共9页
Introduction to Assly Language ProgrammingCCSE.doc_第4页
第4页 / 共9页
Introduction to Assly Language ProgrammingCCSE.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《Introduction to Assly Language ProgrammingCCSE.doc》由会员分享,可在线阅读,更多相关《Introduction to Assly Language ProgrammingCCSE.doc(9页珍藏版)》请在三一办公上搜索。

1、Lab 1: Assembly Language Tools and Data RepresentationContents1.1. Introduction to Assembly Language Tools1.2. Installing MASM 6.151.3. Displaying a Welcome Statement1.4. Installing the Windows Debugger1.5. Using the Windows Debugger1.6. Data Representation1.1 Introduction to Assembly Language Tools

2、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.1 AssemblerAn assembler is a program that converts source-code programs written in assem

3、bly 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 dist

4、ributed by the free software foundation. We will use MASM 6.15.1.1.2 LinkerA linker is a program that combines your programs 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 file

5、s. 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

6、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.1.3 DebuggerA debugger is a program that allows you to trace the execution of a program and examine the content of regis

7、ters 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. The latest version of the 32-bit Windows deb

8、ugger is available for download for free from Microsoft.1.1.4 EditorYou 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, which is distributed as a freeware at http:/www.co

9、ntext.cx. 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.1.2 Lab Work: Installing MASM 6.15Step 1: Download MASM615.exe, a self-extract executable file, from http:/ww

10、w.ccse.kfupm.edu.sa/mudawar/coe205/lab/index.htm .Step 2: Double click on MASM615.exe to extract the files. Specify the installation directory. We recommend using C:Program FilesMASM615 as the destination directory, but any other directory will do.Step 3: Define an environment variable MASMDIR for t

11、he 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.Under Environment Variables, Click on the New button to add a New System Variable. Add MASM

12、DIR as the variable name and the C:Program FilesMASM615 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.Step 4: Edit the Path system variable by inserti

13、ng %MASMDIR%; (dont forget the semicolon) at the beginning of the variable value.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.Step 6: Define a new system variab

14、le 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 PATHThese commands should display the MASMDIR,

15、INCLUDE, LIB, and PATH environment variables as shown below. If the installation steps are done properly, you can start using the MASM commands.1.3 Displaying a Welcome StatementThe first assembly-language program that you will assemble, link, and run is welcome.asm. This program displays a welcome

16、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.TITLE Displaying a Welcoming Message (welcome.asm).686.MODEL flat, stdcall.STACKINCLUDE Irvine3

17、2.inc.dataCR EQU 0Dh ; carriage returnLF EQU 0Ah ; line feedwelcome BYTE Welcome to COE 205,CR,LF BYTE Computer Organization and Assembly Language,CR,LF BYTE Enjoy this course and its lab,CR,LF,0.codemain PROC; Clear the screen call Clrscr ; Call procedure Clrscr; Write a null-terminated string to s

18、tandard output lea edx, welcome ; load effective address of welcome into edx call WriteString ; write string whose address is in edx exitmain ENDPEND main1.3.1 Lab Work: Assembling and Linking a ProgramOpen a Command Prompt and type the following command. This command will assemble and link the welc

19、ome.asm program.make32 welcome1.3.2 Lab Work: Running a ProgramThe 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. Watch the output of this program and write it down in the following box:Console

20、Output1.4 Lab Work: Installing the 32-bit Windows DebuggerThe latest version of the 32-bit Windows debugger is available for download from Microsoft at Alternatively, you can download version 6.5.3.7 (released on June 2005) from http:/www.ccse.kfupm.edu.sa/mudawar/coe205/lab/index.htm.Step 1: Downlo

21、ad the 32-bit debugger installer.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 FilesDebugging Tools for Windows at the end of the Path value.

22、Dont 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 FilesDebugging Tool

23、s for Windows as part of the PATH variable.1.5 Lab Work: Using the 32-bit Windows DebuggerWe 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.a

24、sm 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

25、you step through the execution.1.6 Practice: Data RepresentationBefore going into the details of assembly language programming, it is important that you master skills and develop fluency about data representation. Computer data can be represented in a variety of ways. We will examine the content of

26、memory and registers at the machine level. We will use the binary, decimal, and hexadecimal number systems. Here are some practice exercises:1.6.1 Write each of the following Decimal Numbers in Binary:a)2 = d) 13 = b)7 = e) 27 = c)9 = f) 62 = 1.6.2 Write each of the following Binary Numbers in Decim

27、al:a)00001010 = d) 01010111 = b)00001111 = e) 10000000 = c)00101000 = f) 11000111 = 1.6.3 Write each of the following Binary Numbers in Hexadecimal:a)00001010 = d) 01010111 = b)00001111 = e) 10000000 = c)00101000 = f) 11000111 = 1.6.4 Write each of the following Hexadecimal Numbers in Binary:a)0B =

28、d) 3D15 = b)4C = e) 6E70 = c)AF = f) 8A9B = 1.6.5 Write each of the following Hexadecimal Numbers in Decimal:a)0B = d) 3D15 = b)4C = e) 6E70 = c)AF = f) 8A9B = 1.6.6 Signed Integers: 2s Complement NotationIn mathematics, the negative of a number n is the value when added to n produces zero. For exam

29、ple: 3 + (-3) = 0. Programs often include both subtraction and addition operations. However, the CPU only performs addition internally. When subtracting A B, the CPU performs A + (-B). For example, to subtract 6 4, the CPU does 6 + (-4).When working with binary numbers, how does the CPU compute the

30、negative of a number? The answer is that the CPU computes the 2s complement. The 2s complement is the negative of a number. For example, consider the following 8-bit binary number: 00010110, which is equal to 22 in decimal. The 2s complement is obtained by reversing each bit of a binary number (call

31、ed the 1s complement) and then adding 1. For example,2s complement of 00010110 = 11101001 (1s complement) + 1 = 111010100001011011101010+00000000The carry is 1, but it is ignored, since we are representing the number in 8 bitsSince 00010110 in binary = 22 in decimal, then11101010 in binary = -22 in

32、decimal1.6.7 Write each of the following Integers in 8-bit 2s Complement Notation:a)-1 = d) -62 = b)-17 = e) +127 = c)-19 = f) -128 = 1.6.8 Write each of the following 8-bit Signed Binary Integers in Decimal:a)01011100 = d) 01111110 = b)11011100 = e) 10010001 = c)10001111 = f) 10000000 = 1.6.9 Indic

33、ate the sign for each of the following 16-bit signed hex integers:a)7FB9 d) 8123 b)D000 d) 6FFF 1.6.10 Write each of the following signed integers as 16-bit hexadecimal value:a)-1 = c) -256 = b)-127 = d) -8193 = 1.6.11 Largest and Smallesta)What is the largest positive 8-bit value in binary, hexadec

34、imal, and decimal?b)What is the smallest negative 8-bit value in binary, hexadecimal, and decimal?c)What is the largest positive 16-bit value in binary, hexadecimal, and decimal?d)What is the smallest negative 16-bit value in binary, hexadecimal, and decimal?Review Questions1.Name four software tools used for assembly language programming:2.What is an assembler?3.What is a linker?4.What is a debugger?Programming Exercises1.Modify the welcome.asm program to display a message of your choice.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号