Assembly language uses memory space
In the previous experiment we already know that the C language use register requires us to give the corresponding register name, in the function execution process can correspond.
Let's look at how the C language uses memory space:
We already know that writing a byte content like offset address 2000h, we use the following method:
* ( char *) 0x2000 = " Span class= "PLN" style= "Color:rgb (0,0,0)" >a ";
like 2000 : 0 Write a byte in the following way:
*(char far *)0x20000000=’a’;
With the above two points of knowledge under test:
1, write a program um1.c
Compile, link to the. exe file, and then load it with debug to analyze the main function code
We can find the corresponding C code corresponding to the assembly language
Single-step tracking: Set CS to 0d6c IP 01fa
We can find the assigned value in the appropriate place.
The next few instructions are similar to the above.
2, a program, with a C language implementation in the center of the screen display a green character ' a '
The 0b8000000 in the figure indicates that the first address of the display is followed by a 12-line intermediate address
02 indicates that the property is green and 61 represents the character ' a '.
3, analyze the following assembly code
Compile, link with debug load view the corresponding assembly code
From the image code above, it is easy to know that the C language puts the global variable in the DS:[01A6] data segment, and the beginning of the first definition of the data stored in a lower address than the data defined later, the above A1 offset address is less than A2, and A2 is less than A3.
From the last two instructions can be seen, C language will be local variables stored in the stack, and in accordance with the order of the definition of variables, from the top of the stack according to the B1,B2,B3, you can say, first define which variable, which is placed in the stack of the lower address, that is, the closer to the top of the stack.
As for the push BP mov bp,sp these two instructions, actually we have already contacted in the previous study, the purpose is to protect these return the procedure to need the value, because in later uses the stack the time may break the BP value.
4, analysis of the following program assembly code, thinking about related issues
Compile, link with debug to load the corresponding EXE file
First see calling subroutine call 020a command, find the 020A address to see the corresponding program, we are not difficult to find the code in the use of AX register, we can not be difficult to guess, C language will be stored in the return value in Microsoft Dynamics AX.
5. Understand the use of the malloc function below
We learn the C language to know the use of the malloc function
malloc (size);
malloc allocates a memory space that specifies size bytes to the system request.
Now let's analyze the program,
The first line, which indicates that malloc is requesting space from the 0200:0000 address when the request is made to the memory, this space allows our programmers to use a secure space
Line four, which represents 20 spaces of type char, or 20 bytes, with malloc
Line Five, indicates that the base address of buffer is added 10, that is, from the application of the tenth addresses, the assignment value is zero.
The entire while loop below is for assigning ' a '-' h ' to buffer[0] to buffer[7]
BUFFER[10] is to act as a counter, first this counter is 0, the address buffer is assigned (61h+0) value, and then the Counter plus 1, and then the (61h+1) assigned to the address buffer+1, so in turn, so that the buffer[0] to buffer[7] Store ' a ' B ' C ' ... ' H '.
@yujin753
2015-02-28 22:43
字数 1228
阅读 0
xloading the article picture, please wait a moment ...
Assembly language uses memory space