简单NASM"引导程序"不能正确地访问内存? [英] Simple NASM "boot program" not accessing memory correctly?

查看:175
本文介绍了简单NASM"引导程序"不能正确地访问内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**注意,当我说的引导程序,我的意思不是说引导操作系统的程序。我的意思是,运行当您启动计算机,并做了一个简单的程序。

**Note that when I say boot program, I don't mean a program that boots an OS. I mean, a simple program that runs when you start up the computer and does something.

好吧,所以我不的非常的精通汇编/ NASM,但我想我有一个好足够的把握编写简单的引导程序。

Alright, so I'm not extremely well-versed in Assembly/NASM, but I think I have a good enough grasp on it to write simple boot programs.

好吧,我的认为的我有一个好足够的把握。显然没有。

Well, I thought I had a good enough grasp. Apparently not.

我想我在网上找到了一个简单的引导程序。它运行良好(打印字母'A')。然后我修改它来打印存储在内存中的信。它失败;而不是打印的A,它将显示一个笑脸。 (我发誓,计算机的在笑我现在。)

I tried a simple boot program I found online. It ran fine (prints the letter 'A'). I then modified it to print a letter stored in memory. It failed; instead of printing an 'A', it prints a smiley face. (I swear, the computer's laughing at me right now.)

这是从源文件中的code:

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

如果我取代移动人,[testChar] 移动人,65 ,字母'A'是正确打印。我试着移动内存声明的时候,我已经试过括号或前后位和ORG没有支架的每个组合,我已经试过递增和递减testChar(即[testChar + 1])。每一次,它打印无论是笑脸,逆笑脸(当我增加testChar),或者什么都没有(当我把内存声明code之前,可能是因为没有code正在执行= P) 。我不能让这该死的东西的工作。

If I replace 'move al, [testChar]' with 'move al, 65', the letter 'A' is printed correctly. I've tried moving the memory declaration around, I've tried every combination of brackets or no brackets around BITS and ORG, and I've tried incrementing and decrementing testChar (i.e. [testChar+1]). Every time, it prints either a smiley, an inverse smiley (when I increment testChar), or nothing at all (when I put the memory declaration before the code, probably because no code is being executed =P). I can't get the damn thing to work.

现在,对于规范(因为他们很可能相关的):

Now, for specifications (because they're probably relevant):


  • 我运行一个戴尔Latitude CPi亦配备了Intel Pentium II处理器,因为这是我的一切来测试(我不会跟一般的电脑测试汇编。该死的)。我是pretty肯定说处理器是X86,因为我已经在其上运行的Windows XP,Ubuntu和Arch Linux的。

  • I'm running a Dell Latitude CPi with an Intel Pentium II processor, because that's all I've got to test with (I'm not testing assembler with my normal computer. Hell no.). I'm pretty sure said processor is x86, as I've run Windows XP, Ubuntu and Arch Linux on it.

我目前正在写,用NASM在Arch Linux的编译程序。

I'm currently writing and compiling the programs on Arch Linux using NASM.

引导程序是从软盘上运行

The boot program is run from a floppy disk

我用' NASM -f斌FILENAME 编译code。

I use 'nasm -f bin FILENAME' to compile the code.

然后我从'mtools的'包用'mformat'命令AL通过编译引导程序转移到软盘 mformat -f 1440 -B BOOTPROGRAM答:

I then use the 'mformat' command from the 'mtools' package for AL to transfer the compiled boot program to a floppy disk via 'mformat -f 1440 -B BOOTPROGRAM A:'.

所以,我怎么搞砸了这个时间呢?或者是它与我的处理器/ BIOS有问题?

So, what did I screw up this time? Or is it a problem with my processor/BIOS?

推荐答案

DS很可能充斥着一些垃圾的价值,所以才做的:

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

push cs
pop ds

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

更重要的是,不要相信CS和做的:

Better yet, don't trust CS and do:

xor ax, ax
mov ds, ax

请参阅这个讨论:在某些BIOS可能会使用07c0:0000代替了传统的0000:7c00,特意从CD-ROM使用ElTorito引导时

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

这篇关于简单NASM"引导程序"不能正确地访问内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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