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!
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
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
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.
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.
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.)