Simple NASM “boot program” not accessing memory correctly?

断了今生、忘了曾经 提交于 2019-11-30 21:24:18

DS is probably filled with some garbage value, so just do:

push cs
pop ds

or

mov ax, cs
mov ds, ax
mov es, ax

Better yet, don't trust CS and do:

xor ax, ax
mov ds, ax

See this discussion: some BIOSes may use 07c0:0000 instead of the traditional 0000:7c00, specially when booting from CD-ROM using ElTorito.

This is producing the following code (simply run objdump on your compiled code).

00000000  B40E              mov ah,0xe
00000002  B700              mov bh,0x0
00000004  B307              mov bl,0x7
00000006  A00D7C            mov al,[0x7c0d]
00000009  CD10              int 0x10
0000000B  EBFE              jmp short 0xb
0000000D  41                inc cx ; this is actually your testChar
                                   ; ignore the opcode translation

Now if you are located at 0x7C00, then [0x7c0d] will be the final byte in that (i.e. 0x41 or 65, or ASCII "A"). But if like one of the other contributors (ninjalj) has mentioned you have some odd bios bug that means you are not located at 0x7C00 then [0x7c0d] is anyone's guess.

It ran fine when I ran it the first time! It prints 'A'. Use command nasm [filename.asm] -o [filename.com] -l [filename.lst]

I used nasm OSbad.asm -o OSbad.com . Used MagicISO to make a bootable image file OSbad.iso and used Windows disk burner to burn it to a DVD/RW. Loaded Oracle VM and made a new Virtual Machine with 256 Mb RAM, CD/DVD, Hard disk of 2GB. Booted with DVD and it prints 'A' on the screen.

So I guess you program is working. It must be other things that you are doing that makes it not work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!