assembly Language---using registers

Source: Internet
Author: User
Tags button type


assembly language, using registers This book has already talked about why we use variables-because we store data when we program. We've also learned that in assembly language, we store data in registers and memory spaces.

Let's explore how registers and memory spaces are used in the C language.

1, first in the C:\minic directory of Tc.exe write a ur1.c program

Compile, link into ur1.exe

2, with debug load Ur1.exe, with u command to view ur1.c compiled machine code and assembly code


Based on the experience of our assembly language learning, the main function code should be stored in the Code section, we can be disassembled by the main function to find the corresponding codes.
Then use the R command to view CS

CS=0D6C verified the conjecture.
It needs to be pointed out here that the main function code needs to be carefully looked up and found the same as the UR1 code to confirm the found

3. Print Ur1.exe is loaded and run, the offset address of main

We add the code content after the above program, compile, link and run

As can be seen, the program has the result of generating
According to the experience we have learned, main is equivalent to a label in assembly language, and when we print it prints out its entry address.

4, use Debug to find the corresponding code

Here is a MOV ax,01fa is not in our previous program, it can be assumed that this is the main entrance address to 01FA and our previous operation results more confirmed this conjecture.

5. Study another program to verify our conjecture

Loading the EXE program with debug
Find the appropriate program

Here we can easily see that there is a call command to find the code at 020B as follows:

Here is the entry of the F (void) function below the RET equivalent to the return of the function

So, it's easy to know that when a function is called in C, it is translated into the corresponding assembly code with the call command, and the program ends back with a ret instruction, which is the same as the assembly language we learned before.

+
@yujin753  2015-02-28 22:30 字数 708 阅读 0xloading the article picture, please wait a moment ...

Assembly Language---using registers

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.