"NiTiN" <email@example.com> wrote in message
> I've got some really simple code that boots the system and displays a
> string. I've looked at a couple of examples and I'm aware of the load
> to 0x7c00. My jump references are fine but when I try to access
> variables, I get nulls instead of the actual data.
> Here's the source code:
> bits 16
> org 0x7c00
> jmp start
Here is your problem. The BIOS can have any value it wants
in the CS:IP pair as long as it points to physical address
0x07C00. Period. Usually, there are only two pairs.
07C0:0000h or 0000:7C00h.
As long as you don't use a CS: override, and don't set any
other segment register to the CS value, your boot sector
can't care less what the CS:IP register pair is.
However, if you do have the room in the 512 bytes, it is
a safe bet to do the following:
(I don't know if that is NASM syntax, so make sure)
You can also do a push/push/retf too.
That will make sure that the register pair, cs:ip, is
what you want it to be.
> helloMsg db 'A'
Now, just because you now have CS:IP as you want, or in
the case I usually do, you don't care what CS:IP is, doesn't
mean that the DS register is correct.
Most BIOSes, but not all, and definately not required, set
DS to 0x40 since that was the last place it usually wrote to.
So you must set DS to a known value, and it depends on the
ORG statement you used. If you used ORG 0x7C00, you must
set DS to 0x0000, if you set ORG 0x0000, you must set DS
Again, the value pair you set to DS:ORG doesn't matter as
long as the two combined point to physical address 0x07C00.
You could do something like
and it would work, however, this would be confusing to anyone
reading your code and probably to you in five years, depending
on how your memory was.
> mov al, [helloMsg] ;copy the A
> cmp al, 65
> jne wrongChar
> call printChar ;print the A
> jmp end
> mov al, 66 ;print B if wrong character
> call printChar
> jmp $
> mov ah, 0eh
> ;mov al, 65
> mov bh, 0h
> mov bl, 7h
> int 10h
> ;510 bytes plus the 2 byte signature
> zero_padding: times 510 - ($ - $$) db 0
> ;boot signature
> boot_sig: dw 0xaa55
> The output I get on running this code is 'B' when it should be 'A'. I
> must be missing something.
> My setup is VMWare running on Windows, and an NASM compiler.
> Any help is appreciated.
> (Nitin: 'x' post to alt.lang.asm)
Well, I just noticed this and there is some replies in alt.lang.asm.
Since I don't visit that group near as much as I use to, I will
go ahead and post this message. Hope it helps, but disregard if
it is a bit late.
Forever Young Software
To reply by email, please remove the zzzzzz's
Batteries not included, some assembly required.