I. Lab tasks
1. Exercise 1
Part1: Compile the Assembly source program:
Assume Cs: Code
Code segment
MoV ah, 2
MoV DL, 3
Add DL, 30 h
Int 21 h
MoV ah, 2
MoV DL, 6
Add DL, 30 h
Int 21 h
MoV ah, 4ch
Int 21 h
Code ends
End
PS: I am familiar with MASM, so I used this compiler.
When the call was made, the ends was accidentally converted into an end, and an error was returned. The compilation was successful only after the change.
Part2: compile, connect, run, and debug the source program t1.asm.
(1) run the program and observe the program output results
(2) Change the DL values in the line4 and line9 registers to 0 ~ 9. Re-assemble any number and choose "connection"> "run" to observe the result changes.
(3)use debugto debug the generated Executable File t1.exe
A. Run the R command to view details. 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?
B. 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:
C. Use the ucommand to disassemble t1.exe and observe the source code obtained from the disassembly.
D. Use the T and P commands (use the p command in case of int commands) for single-step debugging and observe the results.
----------------------------------------------
Compile and connect under dosbox
I am not familiar with this part of content. I have made several mistakes.
I forgot ";" when I lost for the first time.
This is the result of running it directly with MASM.
----------------------------------------------
This is the result obtained after the number is changed. We can see that the result of modifying the value in the register DL is also different.
This time, I ran it directly after the Assembly connection, which is consistent with the running result under MASM.
----------------------------------------------
The value of register CX is 0016.
The value of register ds IS 075a.
The Cs value in the register is 076a.
Matching Relationship (CS) = (DS) + 10 h
Here I use the T command and p command for single-step debugging. 3 is displayed after the first p command, and 6 is displayed after the second p command. This should be the origin of Result 36.
----------------------------------------------
Apparently the answer is correct.
PS: When I first saw the experiment, I didn't know what PSP was. I went to the book and Baidu
After the program is added, DS stores the segment address of the memory zone where the program is located. If the offset address of this memory zone is 0, the address of the memory zone where the program is located is DS: 0.
The first 256 bytes in the memory area are PSP. DOS is used to communicate with the program. The back space from 256 bytes stores the program
Therefore, the PSP segment address SA can be obtained from DS. If the PSP offset address is 0, the physical address is Sa × 16 + 0.
Sa is the segment address at which the system allocates memory for the program, that is, the content of the current Register Ds.
----------------------------------------------
Result obtained by decompiling with the u command
2. Exercise 2
Part1: Compile the Assembly source program t2.asm
Assume Cs: Code
Code segment
MoV ax, 0b008h
MoV ds, ax
MoV BX, 0
MoV [BX], 0433 H
Add Bx, 2
MoV [BX], 0436 H
MoV ax, 4c00h
Int 21 h
Code ends
End
PS: I originally planned to use MASM directly, but I keep reporting errors and don't know why, so I changed the method.
I am not familiar with this method. It has been done for a long time and has been wrong.
Part2: assemble, connect, run, and debug the source program.
(1) After the t2.asmis merged, the executable file t2.exe is obtained. Run t2.exe, observe the program running result, and verify whether a red value 36 appears in the upper-left corner of the screen.
(2) if (1) the result is verified, re-open t2.asm and try to connect the 0433 H-> 0432 h of line7 in the source code, 0436 H-> 0439h of line10, and re-connect the assembler later.
Use the CLS command to clear the screen and observe the program running result again.
(3) if (1) the result is verified, re-open t2.asm and try to connect 0433 H-> 0333 h of line7 in the source code, 0436 H-> 0336h of line10, and re-connect the assembler later, so that t2.exe is executable.
Use the CLS command to clear the screen and observe the program running result again.
----------------------------------------------
----------------------------------------------
----------------------------------------------
PS: The color reminds me of the last task in Experiment 1. Changing the value assignment will change the color. Here, the value is changed.
Summary:
(1) Pay attention to the details when coding, such as H and end, and S.
(2) Add ";" to the end of MASM t1.asm.
(3) Register DS and CS meet (CS) = (DS) + 10 h
(4) assigning values to 8-bit registers and 16-bit registers in a register will produce different results.
(5) I am not very clear about why MASM reported an error. I asked others about the compiler.
(6) the code in Exercise 2 changes the color of the running result.
(7) When I did this experiment, I realized the importance of reading a book and watching a PPT after class. When I started this experiment, I found that I could not start it.
(8) The best way to be unfamiliar with things is to connect multiple things.
Experiment 3 programming, compilation, connection, and tracking