Free2Code
The majority of forums are now only available as archives, which means posting/editing is disabled.

The Anything and Everything forum is still open.
 
Time: 2013-05-21, 10:51pm
Why won't this code work?
Subject: Why won't this code work?  ·  Posted: 2005-01-19, 02:43pm
Rank: Unregistered
Hi

I am pretty new to assembly. I am trying to write some real mode bootsector code. I am using NASM.

I seem to be having trouble understanding how NASM or x86 real mode handle segments and offsets. For the moment, I am mixing my code and data into one plain binary file.

To my mind, the following code should work:

Code:
  1. [BITS 16]                 ; real mode is 16 bit
  2. entry:
  3.     mov        ax, cs                ; copy code segment (CS) to AX
  4.     mov        ds, ax                ; copy CS to data segment (DS)
  5.     mov        al, [message]      ; load AL with first byte of message
  6.     mov        ah, 0x0E             ; print byte in AL using BIOS interrupt 10h:0Eh
  7.     mov        bx, 0x07            ; set character attributes (white on black)
  8.     int           0x10                 ; call BIOS interrupt
  9. hang:
  10.     jmp        hang
  11. message:
  12.     db         'Hello World', 0x00
  13. ;plus code to fill up to 512 bytes with 0x55AA at the end - works fine, not important here


When I compile and run this code, my Vmware BIOS prints a single 'S'. I haven't tried it on other BIOS's yet. This is not the intended result. Shouldn't it print an 'H'?

I am aware of an easy workaround. I can just tell NASM to start at 0x07C00 (instead of default 0x00?) by adding a [ORG 0x07C00] to the start, and then setting DS to 0x00, rather than setting it to CS. That's fine, and that's what I do for the moment, but Id still like to know why the above code doesn't work - what am I missing?

When I make a memory reference such as [message], presumably this is just a 'displacement' reference using DS as the segment?

Thanks in advance,
Anonymous Coward

 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

Penguino AVR

Want to learn about robotics or microcontrollers?
Check out the Penguino AVR from our friends at
Icy Labs