Assembly language program debugging strategy in LC3 environment

LC3 is a relatively mature 16-bit assembler running and debugging software. It was developed in 2003 by Yale N. Patt of Texas State University and Sanjay J. Patel of the University of Illinois at Urbana-Champaign, two computer science professors. Convenient assembly language development, compilation and debugging environment. LC3 itself is an analog 16-bit instruction executor referring to the computer's von Neumann architecture, but the assembler written by it can also be used for other computing platforms with slight modifications, and it can also study C language compilation optimization and other issues , which is very suitable for assembler beginners or assemblers. For more details on LC3 please refer to: https://en.wikipedia.org/wiki/LC-3

This software can also be obtained from the following links: https://pan.baidu.com/s/1jJ9dyB0 or ​​http://highered.mheducation.com/sites/0072467509/student_view0/lc-3_simulator.html (LC3 official website)

The software consists of an editor (LC3Edit.exe) and a simulator (Simulate.exe). Because this software is green software, it can be used directly after being downloaded on Windows platform. Please download and install the Unix version from the official website.

Using the LC3 Assembler Editor

First, open LC3Edit.exe to write the assembler, and enter the following code:

.ORIG x3000
ADD R1 R0 R1
LDR R2 R3 0
.END

Here, .ORIG x3000 means that the first line of the program starts executing at memory address x3000. The ADD sentence means that the summation result of the values ​​in the memory (Register) R0 and R1 is stored in R1 (limited to the addition of 16-bit signed numbers). The LDR sentence has a slightly more complicated meaning. It means that the value stored in the R3 memory is used as the address a, load the value stored at address a+0 into R2 memory. Here, the 0 after R3 represents the address displacement (offset), and the value ranges from -32 to 31. .END indicates the end of the program.

Then, click the button "asm" on the right side of the program interface, LC3 will translate the assembler into binary and hexadecimal machine language after saving the program, and generate .obj files for the simulator to run and debug.

Enter image description

Open the file directory where the compiled program is located, and you can see that the binary machine code, hexadecimal machine code, etc. have been automatically translated according to the 16-bit architecture standard.

Enter image description

Click the second yellow open button from left to right on the toolbar and select HelloAsembly.bin to view the binary machine code corresponding to the assembler. The effect is as follows:

Enter image description

Note: If the user has binary or hexadecimal machine code, he can also directly click the "->B" or "->X" button to generate the obj file available for the simulator.

Debugging assembler with LC3

Open Simulate.exe, click the yellow button on the far left, and switch the path of the file dialog box that pops up to the directory where the program is located, and select the .obj file to be debugged.

Enter image description

After opening, the assembler program just now will be loaded into the LC3 instruction executor, as shown in the figure.

Enter image description

Click R0 and R1 at the top of the interface, and enter two numbers to be summed (range -2^16 to 2^15 + 1), in this case 2 and 3 respectively.

Enter image description

After that, click on the left side of the x3002 memory location where the program ends to indicate the end point of program debugging. Then, click R3 and enter any memory address where you want to store data (x3010 is used in this example, be careful not to use the memory location of the program itself, here is the location of x3000 - x3002). And click on the address, enter any number in the range of the short variable (20 in this example). After all is completed, the effect is as follows:

Enter image description Enter image description

Since this program has two assembly instructions, click the third button from left to right (ie step over button, sentence-by-sentence debugging) twice. You can see the effect as follows:

Enter image description

It can be found that the memory R1 has correctly stored the result of 2 + 3, and R2 has also correctly loaded the address in R3 plus the data at the displacement of 0, and the debugging environment has correctly prompted the end of the program. Therefore, the debugging of this program is successful.

In this way, we have taken the first step in learning assembly.

References:

Patt, Yale N.; Patel, Sanjay (2003). Introduction to Computing Systems: From Bits and Gates to C and Beyond. New York, NY: McGraw-Hill Higher Education. ISBN 0-07-246750-9. Retrieved 6 October 2010.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324935317&siteId=291194637