- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已经在 Linux 上完成了一些汇编编程,现在正尝试使用 MASM 在 Windows 上完成。不过,我遇到了几个问题。
(我在这里尝试实现 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 标签,抛出不匹配的宏嵌套等。执行此操作的正确方法是什么?附:我尽量避免使用 MASM 宏,而更喜欢自己编写指令。
有人可以编译这个程序吗?一旦我看到它是如何正确完成的,我就会走上快乐的道路,我将能够做到。是的,我在寻找资源,但在这个问题出现时我仍然在寻找资源。
最佳答案
有人可以编译这个程序吗?
Voilà(评论中的解释):
.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
.code
my_strlen proc
; mov ebp, esp ; function prologue
; push esp
push ebp ; this is a correct prologue
mov ebp, esp
push ebx
push ecx
push esi
mov esi, [ebp+8] ; in [EBP+8] is a pointer
xor ecx, ecx
mov bl, byte ptr [esi]
repea: ; "repeat" is a keyword
cmp bl, 0
jz done
inc ecx
mov bl, byte ptr [esi + ecx] ; increase *esi
jmp repea ; repeat
done:
mov eax, ecx
pop esi
pop ecx
pop ebx
leave ; this is a correct epilogue
ret
my_strlen endp
main proc ; this is better
push offset testString
call my_strlen
; push eax ; StdOut(result)
push offset testString ; The MASM32-function StdOut needs only an ASCIZ-string
call StdOut
push 0
call ExitProcess
main endp
end main
我怀疑你想输出my_strlen的结果。这对于 StdOut
是不可能的,因为 StdOut
需要一个指向 string 的指针。您必须创建一个函数来将 EAX
转换为字符串。
关于windows - 试图找出 MASM 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25796257/
我正在将一个函数从内联汇编移植到 Visual Studio 2013 中的 MASM,并且无法从中获取返回值。 这是 C 调用者和汇编函数原型(prototype): extern "C" void
.model tiny .code org 100h host: mov ah,9 mov dx,offset hi int 21h mov ax,4c00h
我是一个初学者在大会。我试图实现一个函数,找到最大的数组,但得到一个错误:致命错误A1008:不匹配的宏嵌套。你能告诉我我做错了什么吗?
我是汇编方面的初学者。我正在尝试实现一个在数组中查找最大值的函数,但得到一个错误:致命错误A1008:不匹配的宏嵌套。你能告诉我我做错了什么吗?
我被指示用汇编编写一个程序,该程序将执行以下算术运算: ((A + B)/C) * ((D - A) + E) 当没有负值发挥作用时,我已经成功地做到了这一点,但假设 A = 5、B = 4、C =
我决定自学汇编语言。 我已经意识到,如果我尝试更改任何段寄存器的值,我的程序将无法编译。 我发现的每篇文章都说我确实可以更改至少 4 个段寄存器的值,那是什么? 我真的只对为什么此时感兴趣,我没有任何
在保护模式下调用内存地址低于当前函数的函数时,我遇到异常。异常会根据代码配置而有所不同,有时是一般保护故障,有时是无效的操作码等。 这里是一个程序的源代码,该程序在硬件上产生一般保护错误,在 DOSB
我是 assembly 初学者。我正在尝试使用 MASM 在屏幕上打印一封信。我定义了堆栈段,但是当我尝试链接程序时,收到此警告: 链接:警告 L4021:没有堆栈段 但是该程序运行良好!我怎样才能解
我正在尝试查询 FS 段寄存器指向的进程环境 block 中的值。尝试编译包含 fs:[0] 段的代码会导致错误(错误 A2108:使用寄存器假定为错误)。 如何查询段寄存器?! 谢谢 最佳答案 MA
我有一些在x86上进行汇编的示例代码,使用的是我想学习的MASM,但是我很难理解。以下是以下数据段: .data sNum1 word 23,-17 iX dword
我一直在使用 MASM 再次涉足 x86 程序集,但遇到了一个小障碍。希望从纯粹的享受中重新发明轮子。 ASSUME eax:PTR hostent mov ebx, [eax].h_
我正在运行一个程序,要求用户输入要显示的合数的个数。前任。如果用户输入 10,程序将显示前 10 个合数。 我遇到的问题是我的程序在一长列中打印所有值,我需要让输出显示为每行 10 个合数,它们之间至
这是我的第一个问题,希望您能帮助我!我目前正在开发 GameBoy 模拟器并想用 MASM 编写它,为了处理CPU指令,我想创建一个包含变量的数组,以便于访问。 这是我想要实现的示例: assume
我需要从汇编代码中调用将三个整数相加 3 的函数;整数本身在 assembly 部分中设置; 一切看起来都正确,但 masm 函数似乎没有返回正确的值。它存储在 eax 中,应该作为函数值返回,但是在
我在哪里可以找到详细说明 MASM 完整指令集的链接或文档的好站点? 为了提供上下文,我目前正在 VS2008 中处理一个 C++ 项目,并且我已经达到了了解程序集到底在说什么(对于添加上下文)很有用
对汇编还很陌生,玩得很开心。我想将我的程序的功能拆分到多个文件中,特别是通过将相似的功能组合在一起进行组织。这些其他文件将由主文件调用(希望甚至是其他非主文件)。我还没有设法做到这一点,希望得到帮助。
在8086处理器中,我们使用的ic是不同的......我认为它们是16位的......但我们在64位计算机上练习代码......这怎么可能?请解释>>>> MaSm实际上是什么? ?你能解释一下我在哪
我正在尝试用 x86 汇编语言编写一个接受三个参数的函数。是否可以用 MASM 汇编语言定义一个具有多个参数的函数? //this is pseudocode: I'm trying to conve
NASM 和 MASM 汇编器之间的语法差异是什么? 最佳答案 NASM 文档第 2.2 节的标题为 Quick Start for MASM Users其中列出了 NASM 和 MASM 之间的重要
我要编写一个宏,它采用 E,NE,A,B... 作为参数和单个命令,即 mov eax,ebx ,这将如果前面的 cmp 操作设置的条件为真,则执行。 调用示例如下所示。 cmp bx,20 mDoI
我是一名优秀的程序员,十分优秀!