Bring you into the world of Assembly

Source: Internet
Author: User

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

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.