//Delphi 的語法描述PContext = ^TContext;_CONTEXT = record ContextFlags: DWORD; Dr0: DWORD; Dr1: DWORD; Dr2: DWORD; Dr3: DWORD; Dr6: DWORD; Dr7: DWORD; FloatSave: TFloatingSaveArea; SegGs: DWORD; SegFs: DWORD; SegEs: DWORD; SegDs: DWORD; Edi: DWORD; Esi: DWORD; Ebx: DWORD; Edx: DWORD; Ecx: DWORD; Eax: DWORD; Ebp: DWORD; Eip: DWORD; SegCs: DWORD; EFlags: DWORD; Esp: DWORD; SegSs: DWORD;end;
; Test17_1.asm.386.model flat, stdcallinclude windows.incinclude kernel32.incinclude masm32.incinclude debug.incincludelib kernel32.libincludelib masm32.libincludelib debug.lib.data? GlobalVal1 dd ? GlobalVal2 dd ? GlobalVal3 dd ?.codemain proc LOCAL LocalVal1:dword, LocalVal2:dword, LocalVal3:dword ;獲取全局變量地址(地址是順序遞增的): PrintHex offset GlobalVal1 ;00403054 PrintHex offset GlobalVal2 ;00403058 PrintHex offset GlobalVal3 ;0040305C ;獲取局部變量地址(地址是順序遞減的): lea eax, LocalVal1 PrintHex eax ;0012FFBC lea eax, LocalVal2 PrintHex eax ;0012FFB8 lea eax, LocalVal3 PrintHex eax ;0012FFB4 retmain endpend main
.386.model flat, stdcallinclude windows.incinclude kernel32.incinclude masm32.incinclude debug.incincludelib kernel32.libincludelib masm32.libincludelib debug.lib.data val1 dd 111 val2 dd 222 val3 dd 333.codemain proc push val1 push val2 push val3 ;壓棧完畢, 接著出棧 pop val1 pop val2 pop val3 ;查看取回的數(shù)據(jù): PrintDec val1 ;333 PrintDec val2 ;222 PrintDec val3 ;111 ;怎么反了? 這就是常說的 "棧中的數(shù)據(jù)是先進(jìn)后出"! 讓后進(jìn)的先出就好了. retmain endpend main
; Test17_3.asm.386.model flat, stdcallinclude windows.incinclude kernel32.incinclude masm32.incinclude debug.incincludelib kernel32.libincludelib masm32.libincludelib debug.lib.data val1 dd 111 val2 dd 999.codemain proc push val1 push val2 pop val1 pop val2 ;現(xiàn)在 val1 和 val2 的值已經(jīng)交換 PrintDec val1 ;999 PrintDec val2 ;111 retmain endpend main
; Test17_4.asm.386.model flat, stdcallinclude windows.incinclude kernel32.incinclude masm32.incinclude debug.incincludelib kernel32.libincludelib masm32.libincludelib debug.lib.data val1 dd 111 val2 dd 999.codemain proc ;xchg va1, val2 ;指令都不支持對兩個變量直接操作, 需要用個寄存器中轉(zhuǎn)下 mov eax, val1 xchg eax, val2 mov val1, eax PrintDec val1 ;999 PrintDec val2 ;111 retmain endpend main
; Test17_5.asm.386.model flat, stdcallinclude windows.incinclude kernel32.incinclude masm32.incinclude debug.incincludelib kernel32.libincludelib masm32.libincludelib debug.lib.data szText db 'Hello World!', 0.codemain proc ;把字符串中的字符逐個壓入棧中 mov ecx, sizeof szText - 1 ;把字符串長度(將要反復(fù)的次數(shù))給 ecx, 沒包括結(jié)束記號 xor esi, esi ;清空 esi, 準(zhǔn)備用作數(shù)組索引@@: movzx eax, szText[esi] ;循環(huán)讀出并壓棧 push eax inc esi loop @B ;從棧中逐個取出并寫入字符串 mov ecx, sizeof szText - 1 xor esi, esi@@: pop eax mov szText[esi], al inc esi loop @B PrintString szText ;!dlroW olleH retmain endpend main;做這個程序也有更好的方案, 譬如用 movs
聯(lián)系客服