[英]A simple assembly program?
I've recently learned how to use MASM from MSVC++ IDE, and to test whether it works, I would like to run a short program.我最近从 MSVC++ IDE 学习了如何使用 MASM,为了测试它是否有效,我想运行一个小程序。
However, I don't know any assembly yet (that which I do is useless: ie: even though I know what i+=1;
is in C++, I can't do anything without int main()
).但是,我还不知道任何程序集(我所做的是无用的:即:即使我知道i+=1;
在 C++ 中是什么,但如果没有int main()
,我什么也做不了)。
So where can I find a simple assembly program akin to the helloworld program used with C++?那么,我在哪里可以找到类似于 C++ 所用的 helloworld 程序的简单汇编程序? (It doesn't actually have to display "Hello, World,". it just has to do something so that I can make sure the set-up I have works). (它实际上不必显示“Hello, World”。它只需要做一些事情,这样我就可以确保我的设置有效)。
Here is the MASM documentation online: http://web.sau.edu/LillisKevinM/csci240/masmdocs/ 这是在线的MASM文档: http : //web.sau.edu/LillisKevinM/csci240/masmdocs/
Here is the difinitive tutorial on assembly: http://webster.cs.ucr.edu/ 这是关于汇编的明确教程: http : //webster.cs.ucr.edu/
I think that between the two of those you should be able to get up to speed and start writing programs. 我认为在这两者之间,您应该能够掌握并开始编写程序。
To get you into a quick start I would suggest the following sites: RADasm and WinASM . 为了让您快速入门 ,我建议您使用以下站点: RADasm和WinASM 。
From these sites you can find some examples, some prepackaged downloads with IDE and compiler. 在这些站点上,您可以找到一些示例,以及使用IDE和编译器进行的预打包下载。 This way it is actually pretty easy to do some GUI-software early on but be warned, take care to read about x86 assembly. 这样,尽早制作一些GUI软件实际上很容易,但是要注意,请谨慎阅读x86汇编。 Check out wikibooks - x86 assembler . 查看Wikibooks-x86汇编器 。
Try this尝试这个
global _main
_main:
mov ax, 0x01
mov bx, 0x02
inc ax
inc bx
jmp _main
Explanation:解释:
1°_ you're saying to nasm to search for a _main label: global _main
1°_ 你对 nasm 说要搜索 _main label: global _main
2°_ you're declaring the _main
label 2°_ 你在声明_main
label
3°_ you're changing the value of two cpu registers: ax
and bx
to 0x01
and 0x02
respectively 3°_ 您正在将两个 cpu 寄存器的值: ax
和bx
分别更改为0x01
和0x02
4°_ you're incrementing the values of ax
and bx
4°_ 你增加了ax
和bx
的值
5°_ lastly, you're jumping to _main
, this mean you are in a infinite loop 5°_ 最后,您跳转到_main
,这意味着您处于无限循环中
You may find this site interesting: Authoring Windows Applications In Assembly Language . 您可能会发现此站点很有趣: 用汇编语言编写Windows应用程序 。 You can download The Small Is Beautiful Starter Kit which contains a sample application to write a Windows program in assembly. 您可以下载The Small Is Beautiful Starter Kit,其中包含一个示例应用程序,用于以汇编形式编写Windows程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.