注册 登录
编程论坛 汇编论坛

函数调用参数问题

马甲1号 发布于 2011-05-11 16:43, 377 次点击
.386
        .model flat, stdcall
        option casemap:none
;==========================================================

include        windows.inc
include        user32.inc
includelib    user32.lib
include        kernel32.inc
includelib    kernel32.lib
include        gdi32.inc
includelib    gdi32.lib

;==========================================================

        .data?
hInstance    dd    ?
g_hWnd        dd    ?

BALL    struct
    ball_x    dw    ?
    ball_y    dw    ?
    ball_cx    dw    ?
    ball_cy    dw    ?
BALL    ends

ball        BALL    <>
        
        .const
szClassName    db    'DrawBall', 0
szWindowTitle    db    'DrawBall-Demo', 0
szRegClassErr    db    'RegisterClassEx Error', 0
szCreateWndErr    db    'CreateWindowEx Error', 0
szCaptionErr    db    'Error!', 0

;==========================================================
        .code
_WndProc    proc    uses ebx edi esi hWnd, wMsg, wParam, lParam

        LOCAL    @hDc
        LOCAL    @stPaint:PAINTSTRUCT
        
        mov    eax, wMsg
        
        .if    eax ==    WM_PAINT
            invoke    BeginPaint, hWnd, addr @stPaint
            mov    @hDc, eax
        push    50
            push    50
            push    10
            push    10
            push    @hDc
            call    Ellipse
            
            ;invoke    Ellipse, @hDc, 10, 10, 50, 50
            
            invoke    EndPaint, hWnd, addr @stPaint
        .elseif    eax ==    WM_CREATE
            
            mov    ball.ball_x, 10
            mov    ball.ball_y, 10
            mov    ball.ball_cx, 50
            mov    ball.ball_cy, 50
        .elseif    eax ==    WM_CLOSE
            invoke    PostQuitMessage, 0
            invoke    DestroyWindow, hWnd
        .else
            invoke    DefWindowProc, hWnd, wMsg, wParam, lParam
            ret
        .endif
        
        mov    eax, 0
        ret
_WndProc     endp

_WinMain    proc
   
        LOCAL    @stWc:WNDCLASSEX
        LOCAL    @stMsg:MSG
        
        invoke    RtlZeroMemory, addr @stWc, sizeof WNDCLASSEX
        mov    @stWc.cbSize, sizeof WNDCLASSEX
        mov    @stWc.style, CS_HREDRAW or CS_VREDRAW
        mov    @stWc.lpfnWndProc, _WndProc
        push    hInstance
        pop    @stWc.hInstance
        invoke    LoadIcon, hInstance, IDI_APPLICATION
        mov    @stWc.hIcon, eax
        mov    @stWc.hIconSm, eax
        invoke    LoadCursor, hInstance, IDC_ARROW
        mov    @stWc.hCursor, eax
        invoke    GetStockObject, BLACK_BRUSH
        mov    @stWc.hbrBackground, eax
        mov    @stWc.lpszClassName, offset szClassName
        
        invoke    RegisterClassEx, addr @stWc
        .if    eax ==    0
            invoke    MessageBox, NULL, offset szRegClassErr, offset szCaptionErr, MB_OK or MB_ICONINFORMATION
            ret
        .endif
        
        invoke    CreateWindowEx, NULL, offset szClassName, offset szWindowTitle, WS_OVERLAPPEDWINDOW, 100, 100, 600, 400, NULL, NULL, hInstance, NULL
        mov    g_hWnd, eax
        .if    eax ==    NULL
            invoke    MessageBox, NULL, offset szCreateWndErr, offset szCaptionErr, MB_OK or MB_ICONINFORMATION
            ret
        .endif
        
        invoke    ShowWindow, g_hWnd, SW_SHOW
        invoke    UpdateWindow, g_hWnd
        
        .while TRUE
            invoke    GetMessage, addr @stMsg, NULL, NULL, NULL
            .break    .if eax == 0
            invoke    TranslateMessage, addr @stMsg
            invoke    DispatchMessage, addr @stMsg
        .endw
        
        ret
_WinMain     endp

start:
        invoke    GetModuleHandle, NULL
        mov    hInstance, eax
        
        invoke    _WinMain
        invoke    ExitProcess, NULL
        
        end    start
3 回复
#2
马甲1号2011-05-11 16:45
我想把Ellipse函数的参数用BALL结构体变量ball代进入, 但是程序没有画出椭圆

invoke Ellipse, @hDc, ball.ball_x, ball.ball_y, ball.ball_cx, ball.ball_cy
#3
zaixuexi2011-05-11 22:57
程序代码:
BALL    struct
    ball_x    dd    ?   ;自己想一想为什么用dd就可以了
    ball_y    dd    ?
    ball_cx   dd    ?
    ball_cy   dd    ?
BALL    ends
.if    eax ==    WM_PAINT
    invoke    BeginPaint, hWnd, addr @stPaint
    mov    @hDc, eax
    push    ball.ball_cy
    push    ball.ball_cx
    push    ball.ball_y
    push    ball.ball_x
    push    @hDc
    call    Ellipse
#4
马甲1号2011-05-12 11:48
哦, 我明白了, 是操作位数不一样
1