Experiment 3 programming, compilation, connection, and tracking

Source: Internet
Author: User

 

Prerequisites:

A brief process from writing to executing an assembly language program:

1. Compile the Assembly source program;

2. Compile and connect the source program. The executable file contains two parts: 1. Program (instruction mechanical code), data (Program-defined data), and 2. Description

3. Execute the program in the executable file

Textbook p94:

(1) Save the program as a t1.asm file and generate the executable file t1.exe.

Assume Cs: codesg

Codesg segment

MoV ax, 2000 h

MoV SS, ax

MoV sp, 0

Add SP, 10

Pop ax

Pop BX

PUSH AX

Push BX

Pop ax

Pop BX

MoV ax, 4c00h

Int 21 h

Codesg ends

End

 

 

(2) Use debugto track the execution process of t1.exe and write the content of the relevant registers and the top content of the stack after the first execution.

 

 The first four commands only use three t commands. The initialization stack address is: SS: sp = 2000:10;

Use the stack Operation Command to first set the data segment in the stack (2000:0 ~ E) Place the content in Ax (01a3), and use the push command to heap back in BX (0000), so that the offset address in the stack is 0 ~ E. Use the pop command to export the data to ax and BX. Ax = 0000 h and BX = 01a3h.

(3) The first two bytes of PSP are CD 20, and debug‑t1.exe is used to view PSP content.

 

PSP and physical addresses are connected consecutively, but different addresses exist!

Lab content;

1. Exercise 1

Step 2: Compile the Assembly source program t1.asm, as shown in source code 1-1.

 

Figure 1-1 compile source code t1.asm

Step 2: compile, connect, run, and debug the source program t1.asm.

(1) run the program and observe what the program output result is?

Write code in the MASM integration environment:

 

Running result:

 

The upper-left corner of the DOS window shows 36 numbers, which are suspected to be related to the DL data segment.

(2) Change the DL values of line4 and line9 registers to 0 ~ 9 any number in, reassemble → connect → run, observe the result changes.

Modify to 5 and 9 respectively. The execution result is required.

 

In this DOS window, the number 59 appears in the upper-left corner. The result of the two operations is 5, which corresponds to the DL data obtained before the first int 21h, 5, 9, and the DL data obtained before the second int 21 h.

(3) debug the generated Executable File t1.exe with debug.

① Run the R command. Observe the value of Cx in the register, observe the value of DS and CS in the Register, and whether the relationship between them is satisfied (CS) = (DS) + 10 h?

 

As shown in the figure, Cx = 0016 H, cs = 076ah, DS = 075ah, satisfying (CS) = (DS) + 10 h;

② The first two bytes of PSP (program segment prefix) are CD 20. use DEBUG to check the PSP content and verify whether the content is as follows.

 

 

③ Use the U command to disassemble t1.exe and observe the source code obtained from the disassembly.

 

④ Use the T and P commands (use the p command in case of int commands) for single-step debugging and observe the results.

Single-step debugging

It is observed that the corresponding value of DL appears below the execution command P every time int 21 H is encountered.

2. Exercise 2

Step 2: Compile the Assembly source code t2.asm, as shown in the source code 1-2.

 

Note *:

Figure 1-2 compile source code t2.asm

Line6-7 is equivalent to mov [0], 0433 H line9-10 is equivalent to mov [2], 0436 H

There are two reasons for using two commands instead of simply writing them in the above format. One of them is convenient for future circulation; the other is for further explanation in Chapter 5th. For the time being, use this method first.

 

Step 2: compile, connect, run, and debug the source program t2.asm.

(1) Compile and connect t2.asm to obtain the executable file t2.exe. Run t2.exe, observe the program running result, and verify whether a red value of 36 appears in the upper-left corner of the screen.

Note *) Some platforms have some problems when running this program in dosbox. If no results are output in the upper-left corner of the screen, run the t2.exe program and run the CLS command to clear the screen, then run t2.exe.

An error occurred while running the program,

 

Changing to mov [0], 0433 H mov [2], 0436 H also produces an error:

 

However, if you use DEBUG to compile the connection, no error occurs:

 

The generated file is as follows:

 

Run the following command in debug:

 

The red number 36 appears in the upper left corner.

(2) if (1) the result is verified, re-open t2.asm and try to convert the 0433h → 0432 h of line7 in the source code,

Line10 0436h → 0439 h, then re-assemble and connect to get the executable file t2.exe. Use the CLS command to clear the screen and observe the program running result again.

Use NotePad to change it:

 

After modification, re-compile the connection:

 

Run:

 

The red number 29 is displayed in the upper-left corner.

(3) if (1) the result is verified, re-open t2.asm and try to convert the 0433h → 0333 h of line7 in the source code,

Line10 0436h → 0336 h, then re-assemble and connect to get the executable file t2.exe. Use the CLS command to clear the screen and observe the program running result again.

Same as (2) Modify again, compile, and connect again. The execution result is required.

 

From (1) (2) it is not difficult to know That the displayed number is related to the end value in the data segment. Now, after the first three values are modified, the color of the number changes, from 043 to 033, the color changes from red to sky blue.

Conclusion: In summary, int 21h seems to be related to the screen display. Different outputs are made based on ax and BX. Int is short for interupt interruption, int 21h refers to the DOS interrupt call command. According to what we have learned now, to AX = 4c00h, call int 21 H again, and the program ends. However, we can see that when AX = 2, calling int 21h will output the characters.

Why did the mov [BX] And 0433h commands fail to run T2 in the MASM integration experiment environment in Exercise 2?] I do not know this. If you know this, I am looking forward to some answers.

Experiment 3 programming, compilation, connection, and tracking

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.