为什么没有这样的boot loader code的工作? [英] Why doesn't this boot loader code work?

查看:122
本文介绍了为什么没有这样的boot loader code的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的期望是,它打印字符串,但没有什么是打印出来。
当我做字符串短,有时工作,当我再一次让他们,它工作的时候。

我不知道为什么,这是行不通的。

有人能帮助我吗?
谢谢你。

组装code,我使用的是:

(Emacs的23,Ubuntu的10.10,NASM,VirtualBox的OSE)

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;
组织0x7c00
16位
STR:
    DB有人说,世界将在火结束,10,13
    DB冰有人说10,13
    DB从我尝过的欲望,10,13
    DB我认为那些谁赞成火,10,13
    DB但是如果我不得不毁灭两次,10,13
    DB我想我知道够恨,10,13
    DB说,毁灭之冰,10,13
    DB也是伟大的,就足够了。
    DB弗罗斯特 - 火与冰
    0分贝
开始:
    异斧,斧
    MOV DS,AX
    MOV ES,AX
    MOV SI,STR
    异或BX,BX
    MOV啊,为0x0E
打印:
    LODSB; AL =当前字符
    CMP人,0
    JE结束
    INT为0x10
    JMP打印
结束:
    CLI
    HLT    次510 - ($ - $$)0分贝
    DW 0xAA55将
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


解决方案

由于它在开始执行的指令code就在 7c00 。也就是说,不幸的是,在这里你有你的字符串。

,以便它跳转到开始,您应该precede该字符串以 JMP 指令

这通常是一个短跳转 EB XX 后跟一个NOP 90 。有些BIOS可能的坚持的上存在这种形式,即使它并不重要的处理器。

在换句话说,你会寻找类似:

 组织0x7c00
16位
realstart:
    JMP短的启动
    NOP
STR:
    DB有人说,世界将在火结束,10,13
    :
    DB弗罗斯特 - 火与冰
    0分贝
开始:
    异斧,斧
    :

请记住,短期跳转只限于至于什么距离它可以去,大概+/- 128字节,所以你的字符串大小将必然由限制。如果您的BIOS不需要 EB XX 90 格式,你可以做一个普通的跳跃。

您可以尝试其他的事情是 HLT 指令后整个字符串移动到:

 组织0x7c00
16位
开始:
    异斧,斧
    :
结束:
    CLI
    HLT
STR:
    DB有人说,世界将在火结束,10,13
    :
    DB弗罗斯特 - 火与冰
    0分贝

但同样,这取决于你的BIOS不需要在一开始的 JMP / NOP 组合。

My expectation is that it prints a string, but nothing is printed out. When I make the string shorter, it sometimes works, and when I make them longer again, it works sometimes.

I don't know why this isn't working.

Could somebody help me? Thanks.

The assembly 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

解决方案

Because it starts executing code right at the instruction at 7c00. That, unfortunately is where you have your string.

You should precede that string with a jmp instruction so that it jumps to start.

This is usually a short jump EB xx followed by a NOP 90. Some BIOS' may insist on that being of this form even though it doesn't really matter to the processor.

In other words, you'd be looking 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 the short jump is limited as to what distance it can go, roughly +/-128 bytes, so your string size will be necessarily limited by that. If your BIOS doesn't require the EB xx 90 format, you can just do a regular jump.

The other thing you could try is to move the entire string to after the hlt instruction:

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, this depends on your BIOS not requiring the jmp/nop combo at the start.

这篇关于为什么没有这样的boot loader code的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆