如何使用Bochs的运行大会code? [英] How can I use Bochs to run Assembly code?

查看:234
本文介绍了如何使用Bochs的运行大会code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的Bochs作为8086仿真器。有没有一种简单的方法来做到这一点?我要的是一样的东西EMU8086( http://www.emu8086.com/ )。

I want to use Bochs as an 8086 emulator. Is there an easy way to do this? What I want is something like emu8086 (http://www.emu8086.com/).

推荐答案

如果你的程序的初始部分适合在512字节,你不介意限制自己BIOS调用, / 退出的说明,并写入神奇记忆位置为I / O ...然后是的!

If the initial part of your program fits in 512 bytes, and you don't mind restricting yourself to BIOS calls, in/out instructions, and writing to magic memory locations for I/O... Then yes!

假设你使用NASM,这里是一个愚蠢的例子...(警告:我的16位汇编技能不是很大,并那种生疏了,所以它可能不是最好的code)

Assuming you're using NASM, here's a goofy example... (Warning: my 16-bit assembly skills are not very great and kind of rusty, so it might not be the best code.)

[org 7c00h]              ; BIOS will load us to this address

mov ax, 0b800h           ; Console memory is at 0xb8000; set up a segment
mov es, ax               ; for the start of the console text.

;
; Let's clear the screen....
;

xor di, di               ; Start at beginning of screen
mov cx, 80*25            ; Number of chars in the screen
mov al, ' '              ; Space character
mov ah, 0fh              ; Color (white on black)
repne stosw              ; Copy!

;
; Write an 'a' to the screen...
;

mov byte [es:0], 'a'     ; Write an 'a'

sleep:
hlt                      ; Halts CPU until the next external interrupt is fired
jmp sleep                ; Loop forever

times 510-($-$$) db 0    ; Pad to 510 bytes
dw 0aa55h                ; Add boot magic word to mark us as bootable

然后就可以用组合:

Then you can assemble with:

nasm foo.asm

和写这篇文章,以这样的软盘映像(假设一个类Unix系统...)

And write this to a floppy image like this: (Assuming a Unix-type system...)

$ dd if=/dev/zero of=floppy.img bs=512 count=2880
$ dd if=foo of=floppy.img conv=notrunc

现在,你可以在启动的Bochs的软盘映像(或者,如果你把它写入软盘,一个真正的PC上运行的话),它应该写一个'a'到屏幕上。

Now you can boot that floppy image in Bochs (or, if you write it to a floppy, run it on a real PC) and it should write an 'a' to the screen.

请注意,这是通常只有有用的,如果你正在写一个引导程序或操作系统...但它的乐趣,实验,特别是如果你正在学习。

Note that this is normally only useful if you're writing a bootloader or an operating system... But it's fun to experiment with, especially if you're learning.

更新:我看了EMU8086网站...似乎有点对嵌入式使用的x86,而不是面向PC。它看起来像它有模拟硬件的一些有趣的功能。如果你不希望定位的电脑,然后Bochs的不会是必须的兴趣。如果这不是你想要做什么,我同意使用EMU8086本身谁提出的评论者。

Update: I read the emu8086 website... Seems kind of oriented towards embedded use of x86 rather than a PC. It looks like it has some interesting features for simulating hardware. If you're not interested in targeting PCs then Bochs will not be of must interest. If that's not what you want to do, I agree with the commenter who suggested using emu8086 itself.

如果您有兴趣,但个人电脑想要的东西逐步执行程序......我经常用QEMU此目的。它的调试标志(参见下 -d 联机帮助页)足以在组件级别观察一个x86程序的执行状态。 (我甚至已经找​​到了用于调试C语言编写的操作系统内核足够有用的,只要你仔细看的C编译器生成的。)

If you are interested in PCs but want something to step through your programs... I've often used qemu for this purpose. Its debugging flags (see manpage under -d) are sufficient for observing the execution state of an x86 program at the assembly level. (I've even found it useful enough for debugging OS kernels written in C, provided you look very carefully what the C compiler generates.)

这篇关于如何使用Bochs的运行大会code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆