The experiment in this article is to use assembler to implement the function of reverse string sorting.
Actually, it is equivalent to the reverse () function in C language.
Brief description:
Place the ''abcdefhij ''string to the specified memory location, and allocate a memory segment as the stack.
Then, import the string into the stack and then exit the stack to implement reverse string sorting.
The following is the code:
Compile:
Connection:
Debugging:
Initialization phase:
Observe the data in the memory on the right,
End of stack entry:
The string "abcdefghij" has been stored in the memory.
End of stack Exit:
The string is sorted in reverse order.
Implementation principle:
First, define data segments and stacks in the memory;
Place the string content in the memory data segment and stack;
Because the stack feature is backward, first-in-first-out, pay attention to the data location when the stack is released.
Problems:
Although the function is successful, some problems are found during code writing.
You can compile mov [0] And ax in debug.
However, an error is reported during compilation using the MASM compilation tool. The error message is that the scalar value cannot be assigned directly.
You can only change the code
MoV BX, 0
MoV [BX], ax
Use the intermediate register to perform the transition. Why can I compile it in debug?
After several days, I saw the content behind the book and finally understood it.
The original debug and compiler MASM have different processing methods for some commands.
See the following example.
Use debug and MASM to compile the Code:
MoV ax, 2000
MoV ds, ax
MoV Al, [0]
MoV BL, [1]
MoV Cl, [2]
MoV DL, [3]
MASM's explanation of commands:
Explain the commands in debug:
From their machine code, we can see that they have different interpretations of commands like "mov ax, [0.
It can be seen that debug interprets it as "[idata]" is a memory unit, and "idata" is the compilation address of the memory unit;
The compiler interprets "[idata]" as "idata ".
You dare not scan me !!!
Source: http://www.cnblogs.com/zhuojun
Bring you into the world of Assembly