高字和低字参数

时间:2017-09-12 22:21:57

标签: assembly masm

我有一个简单程序的示例代码,用于检查鼠标位置,记下X和Y坐标,并检查鼠标左键是否已关闭。

.386
.model  flat, stdcall
option  casemap :none

include     bones.inc

.code
start:
invoke  GetModuleHandle, NULL
mov hInstance, eax
invoke  InitCommonControls
invoke  DialogBoxParam, hInstance, IDD_MAIN, 0, offset DlgProc, 0
invoke  ExitProcess, eax

DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
mov eax,uMsg

.if eax == WM_INITDIALOG

.elseif eax == WM_LBUTTONDOWN ; when left button is down
    invoke SetDlgItemText, hWin, 1001, addr Msg1
.elseif eax == WM_LBUTTONUP ; when left button is up
    invoke SetDlgItemText, hWin, 1001, addr Msg2
.elseif eax == WM_MOUSEMOVE
    xor ecx, ecx ; clear ecx register
    mov cx, WORD PTR lParam ; copy low-word of lParam to cx  <---- this is line that is bothering me
    invoke SetDlgItemInt, hWin, 1002, ecx, FALSE ; set integer in control
    xor ecx, ecx ; zerujemy rejestr ecx
    mov cx, WORD PTR lParam+2 ; copy high-word of lParam to cx <--- this line is bothering me as well
    invoke SetDlgItemInt, hWin, 1003, ecx, FALSE ; set integer in control
.elseif eax == WM_CLOSE
    invoke  EndDialog, hWin, 0
.endif

xor eax,eax
ret
DlgProc endp

end start

这是我在第一行感兴趣的断点上的ollydebugger屏幕截图: enter image description here

我的问题是:

1)这一行究竟是什么:MOV CX,WORD PTR SS:[EBP + 14]? 是这样的:复制到CX寄存器的单元格号EBP + 14的值?所以,如果EBP显示1号细胞,那么源细胞数是15?

2)因此,在我的情况下,如果截图:EBP值是(0001 1001 1111 1011 1011 0000)(19FBB0h)是低字(0000 0000 0001 1001)和高字(1111 1011 1011 0000)?如果不是,我怎么能学到这个?

3)作者如何知道正确的值分别是高低字?

4)为什么mov cx,WORD PTR lParam + 2?这个+2困扰着我。如果lParam是DWORD(32位),为什么偏移量是+2?高句子不应该是+16吗?

提前谢谢

编辑:如果需要,这是bones.inc文件:

include     windows.inc
include     user32.inc
include     kernel32.inc
include     comctl32.inc    ;windows common controls

includelib  user32.lib
includelib  kernel32.lib
includelib  comctl32.lib    ;windows common controls

DlgProc     PROTO   :DWORD,:DWORD,:DWORD,:DWORD

.const
IDD_MAIN    equ 1000

.data
Msg1 db "Lewy przycisk myszy jest wciśnięty",0
Msg2 db "Lewy przycisk myszy jest zwolniony",0

.data?
hInstance   dd  ?

1 个答案:

答案 0 :(得分:4)

  1. 否。 ebp=19FBB0h ebp+14h=19FBC4h 004200CFh,其内容为</a>
  2. 作者已阅读documentation for WM_MOUSEMOVE
  3. 偏移量以字节为单位,而不是位。 +2个字节是+16位,或+1个字。
相关问题