Cygwin:汇编语言开发?
首先,我不确定这是否应该成为我的线程的一部分 昨天开始程序集和堆栈,但我认为 我在这里问的问题完全不同。
我一直在尝试了解 Cygwin 到底是什么,通过 维基百科和谷歌,我运气不太好。 我刚刚开始使用 gcc 在 Linux 上进行汇编编程 气体装配工。 我在午餐时在工作时使用一台机器 上面只有Windows。 我想练习一些组装 这里的语言编程所以我认为 Cygwin 可能能够 帮助。
我错误地相信我在 Linux 中编写的代码 可以使用 Cygwin 在 Windows 中编译和运行。 Cygwin 允许我很好地编译代码:
as someAssmProg.as -o someAssmProg.o
ld someAssmProg.o -o someAssmProg
但是如果我尝试在 Cygwin 下运行代码,
./someAssmProg
我会收到“发生未处理的 win32 异常”消息
现在我假设这是因为我正在编写的代码是 适用于 Linux。 我以为 Cygwin 会处理 有了这个。 Cygwin 真的只是用来开发吗 以 Unix 风格的命令行方式运行 Windows 应用程序?
我再次知道这对于这里的大多数人来说可能是显而易见的,但是 我真的很困惑!
PS 我之前曾在 Windows 上尝试过 AndLinux,但安装量相当大。
Firstly I'm not sure if this should be part of the thread I
started yesterday on assembly and the stack but I think
the question I'm asking here is quite different.
I'm been trying to understand what exactly Cygwin is, via
Wikipedia and Google, I'm not having much luck.
I've just begun assembly programming on Linux using the gcc
gas assembler. I'm using a machine at work during lunch that
only has Windows on it. I wanted to practice some assembly
language programming here so I thought Cygwin might be able
to help.
Mistakenly I believed that the code I was writing in Linux
could just be compiled and run in Windows using Cygwin.
Cygwin allows me to compile the code fine:
as someAssmProg.as -o someAssmProg.o
ld someAssmProg.o -o someAssmProg
But if I try to run the code under Cygwin,
./someAssmProg
I get a "unhandled win32 exception occured" message
Now I am assuming this is because the code I'm writing is
intended for Linux. I thought though that Cygwin would deal
with this. Is Cygwin just really meant to be used to develop
Windows applications in a Unix style command line way?
Again I know this is probably obvious to most folks here but
I'm genuinely confused!
P.S I've tried AndLinux before for Windows, but it's quite a hefty install.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Cygwin 是一个运行时层,它在 Windows 上提供来自 Unix/Linux 世界的库和软件。 它不会让你的汇编代码运行,因为底层的操作系统仍然是Windows,所以所有的中断等仍然是Windows版本,而不是Linux版本。 此外,如果您确实想在 Windows 上运行汇编程序,则必须采取与 Linux(或 DOS)中不同的方式进行操作。
Cygwin is a runtime layer that provides libraries and software from the Unix/Linux world on Windows. It will not allow your assembler code to run, as the OS is still Windows underneath, so all the interrupts, etc. are still the Windows, not Linux, versions. In addition, if you really want to run assembler on Windows, you have to do things a lot differently than you do in Linux (or DOS, for that matter).
您完全可以在 Cygwin 中运行汇编程序。 我猜你的加载失败了,因为在 Windows 执行进程和进入
main
函数之间必须发生很多事情。 当 gcc 将程序集作为输入时,它将链接到适当的样板代码以生成有效的可执行文件。这是一个示例汇编程序。 将其另存为 hello.s:
然后运行它
处理器汇编指令的参考包含在 AMD64 架构程序员手册。 C 调用约定记录在 此页面来自互联网档案馆; 也许你可以找到一个仍然有图像的类似的?
请注意,Cygwin 目前仅进行 32 位汇编; (非消费者)世界现在都是 64 位,在现代处理器的 64 位模式下,您有更多的寄存器和不同的调用约定。
You can totally run assembly programs in Cygwin. I’m guessing that your load failed because there’s a bunch of stuff that has to happen between when Windows executes a process and when you get to the
main
function. When gcc is given assembly as input, it will link in the appropriate boilerplate code to generate a valid executable.Here’s a sample assembly program. Save it as hello.s:
then run it with
The reference for your processor’s assembly instructions are contained in the AMD64 Architecture Programmer’s Manual. The C calling convention is documented in this page from the Internet Archive; maybe you can find a similar one that still has the images?
Note that Cygwin will only do 32-bit assembly right now; the (non-consumer) world is all 64 bits now, and in 64-bit mode on modern processors you have many more registers and different calling conventions.
最好的方法是安装一个虚拟机(使用 VirtualBox 或类似的东西)并在其下完整安装 Linux。 听起来这可能太重了,无法满足您的要求,但这是我目前唯一的建议。
The best way to do it really is to install a VM (using VirtualBox or somesuch) with a full install of Linux under it. It sounds like that may be too heavy to meet your requirements, but that's the only suggestion I have at the moment.
嗨,我遇到了类似的问题,但能够使用 -mconsole 解决它
在此 cygwin 会话中,选项首先编译文件 foo.c,然后使用 gdb 调试器运行我希望这会对您有所帮助
hi i had a similar problem but was able to figure it out using the -mconsole
option in this cygwin session a file foo.c is first compiled and than run with the gdb debugger i hope that will help you