组装原型说明

发布于 2024-07-13 04:50:11 字数 1289 浏览 9 评论 0原文

我正在 MASM32 Assembly 中写一篇作业,我几乎完成了它,但我有 2 个问题我似乎无法回答。 首先,当我编译时,我收到消息:

INVOKE 需要原型 流程

无效的指令操作数

是由于这段代码造成的:

.data?
Freq    DWORD ?
Time1   DWORD ?
Time2   DWORD ?

.code
start:
invoke QueryPerformanceFrequency, addr Freq
invoke QueryPerformanceCounter, addr Time1 

现在,我知道

INVOKE 指令必须位于前面 通过程序的 PROTO 语句 被召唤。

但即使我找到了 PROTO 语句的语法:

label PROTO [distance] [langtype] [,[parameter]:tag]

我不明白我应该写什么才能使它工作,我什至不知道是什么导致了第二个错误或如何修复它...... =/


编辑

我已经有了这些库,还有:

.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib

我正在 Windows Vista 下工作,以防万一也有帮助。


编辑 2

如果我在 .data 之后写入 Freq :QWORD,我会收到以下错误消息:

使用寄存器假定为错误

,并且我应该在哪里添加

QueryPerformanceCounter PROTO :DWORD

据我所知没有犯错误但我仍然不确定更改任何内容(我将其放置在 .data 之前和库之后)。

I am writing an assignment in MASM32 Assembly and I almost completed it but I have 2 questions I can't seem to answer. First, when I compile I get the message:

INVOKE requires prototype for
procedure

&

invalid instruction operands

the first is due to this piece of code:

.data?
Freq    DWORD ?
Time1   DWORD ?
Time2   DWORD ?

.code
start:
invoke QueryPerformanceFrequency, addr Freq
invoke QueryPerformanceCounter, addr Time1 

now, I know that

The INVOKE directive must be preceded
by a PROTO statement for the procedure
being called.

but even though I found out the syntax for the PROTO statement:

label PROTO [distance] [langtype] [,[parameter]:tag]

I don't understand exactly what I should write so as to make it work and I don't even know what is causing the second error or how to fix it...=/


Edit

I already have those libraries and these also:

.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib

I'm working under Windows Vista just in case that helps as well.


Edit 2

If I write the Freq :QWORD after the .data I get this error message:

use of register assumed to ERROR

and also where should I add the

QueryPerformanceCounter PROTO :DWORD

Which as far as I know didn't make an error but still I'm not sure changed anything (I placed it before .data and after the libraries).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生寂 2024-07-20 04:50:11

为了调用外部 API,您需要包含适当的 *.inc 文件以及相应的 *.lib 文件。
尝试将这些语句添加到您的列表中:(

include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

假设 \masm32 指的是您的 masm32 目录)

更新:
原型定义基本上告诉汇编器各个函数在堆栈上需要多少个参数。 在您的情况下,API 期望堆栈上有一个 32 位参数,原型如下所示:

QueryPerformanceCounter PROTO :DWORD

Update2:
为了使用性能计数器 API,您需要一个四字。 原因是,API 需要一个指向四字(64 位)的指针作为参数(因此原型中的 DWORD):

LOCAL Freq  :QWORD
invoke QueryPerformanceFrequency, ADDR Freq

这应该可以解决问题。

更新3:
所以这是一个对我有用的完整示例:

    .486
    .model flat, stdcall
    option casemap :none

    include \masm32\include\windows.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\masm32.inc

    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\masm32.lib

    doPerf     PROTO

.code

start:

    invoke doPerf
    invoke ExitProcess,eax

    doPerf proc

        LOCAL Freq  :QWORD
        invoke QueryPerformanceFrequency, ADDR Freq
        mov esi, dword ptr Freq
        mov edi, dword ptr Freq+4

        ret

    doPerf endp

end start 

我想就是这样:)
ESI 和 EDI 现在包含结果。

In order to call an external API you need to include the appropriate *.inc file as well as the respective *.lib file.
Try to add these statements to your listing:

include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

(assuming \masm32 referes to your masm32 dir)

Update:
The prototype definition basically tells the assembler how many parameters the respective function expects on the stack. In your case the API expects one 32bit parameter to be on the stack, which is reflected by the prototype like this:

QueryPerformanceCounter PROTO :DWORD

Update2:
In order to use the performance counter API you need a quadword. The reason is, that the API expects a pointer to a quadword (64 bit) as the parameter (therefore the DWORD in the prototype):

LOCAL Freq  :QWORD
invoke QueryPerformanceFrequency, ADDR Freq

This should do the trick.

Update3:
So here's a complete example which works for me:

    .486
    .model flat, stdcall
    option casemap :none

    include \masm32\include\windows.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\masm32.inc

    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\masm32.lib

    doPerf     PROTO

.code

start:

    invoke doPerf
    invoke ExitProcess,eax

    doPerf proc

        LOCAL Freq  :QWORD
        invoke QueryPerformanceFrequency, ADDR Freq
        mov esi, dword ptr Freq
        mov edi, dword ptr Freq+4

        ret

    doPerf endp

end start 

I guess that's it :)
ESI and EDI now contain the result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文