Why does this bootloader code not work?

My expectation is that it prints a line but nothing prints. When I make a line shorter, it sometimes works, and when I make them longer, it works sometimes.

I do not know why this does not work.

Can someone help me? Thanks.

The build code I'm using is:

(Emacs 23, Ubuntu 10.10, nasm, VirtualBox OSE)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; org 0x7c00 bits 16 str: db "Some say the world will end in fire",10,13 db "Some say in ice",10,13 db "From what I've tasted of desire",10,13 db "I hold with those who favor fire",10,13 db "But if I had to perish twice,",10,13 db "I think I know enough of hate",10,13 db "To say that for destruction ice",10,13 db "is also great and would suffice." db "Robert Frost - Fire and Ice" db 0 start: xor ax,ax mov ds,ax mov es,ax mov si, str xor bx,bx mov ah, 0x0e print: lodsb ;al = current char cmp al, 0 je end int 0x10 jmp print end: cli hlt times 510 - ($-$$) db 0 dw 0xAA55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
+2
source share
2 answers

Since he begins to execute code directly in the team at 7c00 . This, unfortunately, is where you have your string.

You must precede this line with the jmp statement so that it jumps to start .

This is usually a short EB xx jump followed by a NOP 90 . Some BIOSes may insist on having this shape, even if it does not really matter to the processor.

In other words, you will look for something like:

 org 0x7c00 bits 16 realstart: jmp short start nop str: db "Some say the world will end in fire",10,13 : db "Robert Frost - Fire and Ice" db 0 start: xor ax,ax : 

Just keep in mind that a short jump is limited with respect to how far it can go, approximately +/- 128 bytes, so the size of your string will be necessarily limited by this. If your BIOS does not require EB xx 90 format, you can simply perform the usual transition.

Another thing you could try is to move the entire line after the hlt :

 org 0x7c00 bits 16 start: xor ax,ax : end: cli hlt str: db "Some say the world will end in fire",10,13 : db "Robert Frost - Fire and Ice" db 0 

but, again, it depends on your BIOS, which does not require jmp/nop combos at the beginning.

+9
source

A good way to make sure paxdiablo and Igor Skochinsky are correct is to put the text string in a file and then run it carefully with a disassembler. Shorter lines that print correctly should be parsed into a line of code that doesn't hurt anything. Shorter lines that fail and a longer line will include either illegal instructions, jump or call instructions, or even have a 2 or 3 byte instruction at the end, which at the beginning uses the opcode for the "xor ax,ax" your code.

+1
source

All Articles