Simple "NASM" boot program, wrong access to memory?

** Please note that when I say a boot program, I do not mean a program that loads the OS. I mean, a simple program that starts when the computer starts and does something.

Good, so I'm not very good at Assembly / NASM, but I think I understand it well enough to write simple boot programs.

Well, I thought I had enough grip. Apparently not.

I tried a simple boot program that I found on the Internet. It went fine (typing the letter "A"). Then I changed it to print a letter stored in memory. This failed; instead of typing "A", he prints a smiley face. (I swear the computer is laughing at me right now.)

This is the code from the source file:

[BITS 16]    ; We start up in 16-bit real mode
[ORG 0x7C00] ; We're booted into memory at this address. (Or so I'm told)

mov ah, 0x0E       ; Teletype command
mov bh, 0x00       ; Page number
mov bl, 0x07       ; Attributes (7 == white foreground, black background)
mov al, [testChar] ; Character to print; load it from the memory referenced by testChar.

int 0x10  ; Tell the BIOS to execute the teletype command.

jmp $  ; Infinite loop prevents us from going off and executing the other junk in memory

testChar db 65  ; This is the character we want to print. 'A'.

; The following code pads the rest of the outputted binary file
;   and concludes it with the bootloader signature so I don't have
;   to do so manually.
times 510-($-$$) db 0
dw 0xAA55

If I replace " move al, [testChar] " with " move al, 65 ", the letter "A" will be printed correctly. I tried moving the memory declaration around, I tried every combination of brackets with or without brackets around BITS and ORG, and I tried to increase and decrease testChar (ie [TestChar + 1]). Each time it prints either a smiley or a reverse smiley (when I increase testChar), or nothing at all (when I add a memory declaration in front of the code, possibly because no code is executed = P). I can't get this damn thing to work.

Now for the specifications (because they are probably relevant):

  • Dell Latitude CPi Intel Pentium II, , ( . ). , x86, Windows XP, Ubuntu Arch Linux.

  • Arch Linux NASM.

  • ' nasm -f bin FILENAME' .

  • "mformat" "mtools" AL " mformat -f 1440 -B BOOTPROGRAM A:.

, ? /BIOS?

+5
3

DS, , , :

push cs
pop ds

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

, CS :

xor ax, ax
mov ds, ax

. : BIOS 07c0: 0000 0000: 7c00, - ElTorito.

+3

( objdump ).

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

, 0x7C00, [0x7c0d] ( 0x41 65, ASCII "A" ). - (ninjalj) , - BIOS, , 0x7C00, [0x7c0d] .

0

, ! "A". nasm [filename.asm] -o [filename.com] -l [filename.lst]

nasm OSbad.asm -o OSbad.com. MagicISO, OSbad.iso Windows- DVD/RW. Oracle VM 256 , CD/DVD, 2 . DVD, "A" .

, , . , , .

0
source

All Articles