Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the initial part of your program fits in 512 bytes, and you don't mind restricting yourself to BIOS calls, <code>in</code>/<code>out</code> instructions, and writing to magic memory locations for I/O... Then yes!</p> <p>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.)</p> <pre><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 </code></pre> <p>Then you can assemble with:</p> <pre><code>nasm foo.asm </code></pre> <p>And write this to a floppy image like this: (Assuming a Unix-type system...)</p> <pre><code>$ dd if=/dev/zero of=floppy.img bs=512 count=2880 $ dd if=foo of=floppy.img conv=notrunc </code></pre> <p>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.</p> <p>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.</p> <p><b>Update:</b> 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.</p> <p>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 <code>-d</code>) 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.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload