自己看吧,不解释:
程序代码:
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.50727.1
TITLE Test.cpp
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES
PUBLIC _main
PUBLIC ??_C@_03POMAGKDD@xyz?$AA@ ; `string'
PUBLIC ??_C@_0L@ONEJGDMG@?$CFs?5?9?9?$DO?5?$CFd?6?$AA@ ; `string'
EXTRN __imp__printf:PROC
EXTRN __imp__malloc:PROC
EXTRN __RTC_CheckEsp:PROC
EXTRN __RTC_InitBase:PROC
EXTRN __RTC_Shutdown:PROC
; COMDAT rtc$TMZ
rtc$TMZ SEGMENT
__RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown
rtc$TMZ ENDS
; COMDAT rtc$IMZ
rtc$IMZ SEGMENT
__RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase
rtc$IMZ ENDS
; COMDAT ??_C@_0L@ONEJGDMG@?$CFs?5?9?9?$DO?5?$CFd?6?$AA@
CONST SEGMENT
??_C@_0L@ONEJGDMG@?$CFs?5?9?9?$DO?5?$CFd?6?$AA@ DB '%s --> %d', 0aH, 00H ; `string'
CONST ENDS
; COMDAT ??_C@_03POMAGKDD@xyz?$AA@
CONST SEGMENT
??_C@_03POMAGKDD@xyz?$AA@ DB 'xyz', 00H ; `string'
CONST ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File test.cpp
; COMDAT _main
_TEXT SEGMENT
_head$ = -8 ; size = 4
_main PROC ; COMDAT
; 16 : {
push ebp
mov ebp, esp
sub esp, 204 ; 000000ccH
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-204]
mov ecx, 51 ; 00000033H
mov eax, -858993460 ; ccccccccH
rep stosd
; 17 : struct stu_power *head; //head存放 stu_power的首地址
; 18 :
; 19 : head = (struct stu_power *) malloc(LEN);
mov esi, esp
push 12 ; 0000000cH
call DWORD PTR __imp__malloc
add esp, 4
cmp esi, esp
call __RTC_CheckEsp
mov DWORD PTR _head$[ebp], eax
; 20 :
; 21 : head->stu_name = "xyz"; //malloc(LEN) 是12字节,malloc申请的内存是固定的呀, stu_name是一个字符指针啊,在未指向存储空间的时候怎么能赋值呢。
mov eax, DWORD PTR _head$[ebp]
mov DWORD PTR [eax], OFFSET ??_C@_03POMAGKDD@xyz?$AA@
; 22 : //那为什么head->stu_name还可以输入任意长度的字符串啊
; 23 : head->power = 999;
mov eax, DWORD PTR _head$[ebp]
mov DWORD PTR [eax+4], 999 ; 000003e7H
; 24 :
; 25 : printf("%s --> %d\n", head->stu_name, head->power);
mov esi, esp
mov eax, DWORD PTR _head$[ebp]
mov ecx, DWORD PTR [eax+4]
push ecx
mov edx, DWORD PTR _head$[ebp]
mov eax, DWORD PTR [edx]
push eax
push OFFSET ??_C@_0L@ONEJGDMG@?$CFs?5?9?9?$DO?5?$CFd?6?$AA@
call DWORD PTR __imp__printf
add esp, 12 ; 0000000cH
cmp esi, esp
call __RTC_CheckEsp
; 26 :
; 27 : return 0;
xor eax, eax
; 28 : }
pop edi
pop esi
pop ebx
add esp, 204 ; 000000ccH
cmp ebp, esp
call __RTC_CheckEsp
mov esp, ebp
pop ebp
ret 0
_main ENDP
_TEXT ENDS
END
[
本帖最后由 TonyDeng 于 2012-10-31 01:12 编辑 ]