gpt4 book ai didi

MASM. Getting error "Unmatched macro nesting"(MASM.获取错误“不匹配的宏嵌套”)

转载 作者:bug小助手 更新时间:2023-10-28 09:32:15 33 4
gpt4 key购买 nike



I am a beginner in Assembly. I am trying to implement a function that finds the maximum in an array, but getting a error: fatal error A1008: unmatched macro nesting

我是一个初学者在大会。我试图实现一个函数,找到最大的数组,但得到一个错误:致命错误A1008:不匹配的宏嵌套


Could you say me what am I doing wrong?

你能告诉我我做错了什么吗?



#include <stdio.h>

extern "C" int search_max(int* arr, int size);

int main()
{
int arr[] = {1, 2, 3, 6, 8, -1, 0};
int a = search_max(arr, 7);
printf("%d", a);
return 0;
}




.data
b byte 4
.code
search_max proc
mov rax, [rcx]
while:
cmp rax, [rcx]
jna assign
jmp without_assign
assign:
mov rax, [rcx]
without_assign:
dec rdx
jz end_while
add rcx, b
jmp while
end_while:
ret
search_max endp
end

更多回答

b byte 4 likely you wanted b equ 4. Note that your code is using 64 bit operations while int is just 32 bits.

注意,您的代码使用的是64位运算,而int只有32位。

@Jester This doesn't solve the problem

@杰斯特,这并不能解决问题

That's why it was just a comment. It solves other problems, which the code in your answer still has. (You only fixed b, not the fact that you're doing 8-byte loads overlapping by 4 bytes. Your C is expecting you to be working on 4-byte elements. Single-step with a debugger and watch register values. You want mov eax, [rcx] and so on. Also, add rcx, 4; you don't need to and shouldn't put that constant in data memory.)

这就是为什么它只是一个评论。它解决了您答案中的代码仍然存在的其他问题。(您只修复了b,而没有修复您正在执行的8字节加载与4字节重叠的事实。您的C期望您处理4字节的元素。使用调试器单步执行并监视寄存器值。你想要mov eax、[RCX]等等。另外,添加RCX,4;您不需要也不应该将该常量放入数据内存。)

peter-cordes, I just started learning assembler. There are many errors in the code, you are right. But I decided to ask this question because I couldn’t run my code. Now the code runs, although it doesn't work correctly

彼得-科德斯,我才刚开始学汇编。代码中有很多错误,你是对的。但我决定问这个问题,因为我不能运行我的代码。现在代码运行了,尽管它不能正常工作

优秀答案推荐

I found the bug. It seems using while keyword was a mistake.

我找到了窃听器。使用While关键字似乎是一个错误。


.data
b qword 4
.code
search_max proc
dec rdx
mov rax, [rcx]
start_while:
cmp rax, [rcx]
jbe assign
jmp without_assign
assign:
mov rax, [rcx]
without_assign:
dec rdx
jz end_while
add rcx, b
jmp start_while
end_while:
ret
search_max endp
end

更多回答

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com