【发布时间】:2014-09-11 20:20:46
【问题描述】:
我已经在 Linux 上进行了一些汇编编程,现在正尝试在 Windows 上使用 MASM 进行。不过,我遇到了几个问题。
(这里我正在尝试实现 strlen() 函数。我知道函数逻辑/指令不是最佳的,但我只是想弄脏一些东西,以便继续实现其他 C 库函数.)
.386
.model flat, stdcall
option casemap:none
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib
.data
testString db "test string", 0 ; 0 -> terminator
.code
my_strlen proc
mov ebp, esp ; function prologue
push esp
push ebx
push ecx
xor ecx, ecx ; set count to 0
mov bl, byte ptr [ebp + 8] ; set low of b to 1st character
repeat:
cmp bl, 0 ; if null terminator, return
jz done
inc ecx ; increase count
mov bl, byte ptr [ebp + 8 + ecx] ; increase *ebx
jmp repeat ; repeat
done:
mov eax, ecx ; return count
pop ecx ; function epilogue
pop ebx
pop esp
ret
my_strlen endp
main:
push offset testString ; result = my_strlen(testString)
call my_strlen
push eax ; StdOut(result)
call StdOut
push 0 ; ExitProcess(0)
call ExitProcess
end main
当我尝试编译时,它似乎不喜欢我的 jmp 标签,抛出不匹配的宏嵌套等。这样做的正确方法是什么? p.s.我尽量避免使用 MASM 宏,而是自己编写指令。
有人可以编译这个程序吗?一旦我看到它是如何正确完成的,我就会走上快乐的道路,我将能够做到。是的,我在寻找资源,但仍然存在这个问题。
【问题讨论】:
-
我认为“重复”可能是一个糟糕的选择。我认为它是一个 MASM 关键字,用于管理宏的重复。
-
@Harry 在我开始我的实验之前,请试试这个:将单词
repeat:更改为George:之类的东西。Repeat这个词对MASM的Macro部分有特定的含义 -
@IraBaxter 请关闭你的读心调制解调器!
-
您应该包含您收到的确切错误消息。如果你得到很多,你只能包括前几个。