"times 510-($-$$)db 0&";不起作用 [英] "times 510-($-$$) db 0" does not work

查看:376
本文介绍了"times 510-($-$$)db 0&";不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习引导扇区.我从 NASM 网站下载了nasm-installer-x64.exe.我的操作系统是win7-64bit.当我运行以下代码时,它将无法正常工作

I am learning about boot sectors. I downloaded nasm-installer-x64.exe from the NASM website. My operating system is win7-64bit. When I run the following code it does not work correctly

mov ah, 0x0e;

mov al, the_secret;
int 0x10;

mov al, [the_secret];
int 0x10;

mov bx, [the_secret];
add bx, 0x7c00;
mov al, [bx];
int 0x10;

mov al, [0x7c1e];
int 0x10;

jmp $;

the_secret:;
    db 'X';

times 510-($-$$) db 0;
dw 0xaa55;

推荐答案

我不相信times 510-($-$$) db 0有什么问题.在我看来,您正在尝试找到访问变量the_secret的适当方法,然后将其显示在屏幕上.我将基于这种尝试提供一种最有希望的机制:

I don't believe there is anything wrong with times 510-($-$$) db 0. It seems to me your are attempting to find the proper way to access the variable the_secret and then display it to the screen. I'll provide one mechanism based on this attempt which has the most promise:

mov al, [the_secret];
int 0x10;

如果正确设置了 DS ,请使用org 0x7c00设置起点,并确保将 BH 设置为要写入的页码(您要0),那么以下代码应该可以工作:

If you set up DS properly, set an origin point using org 0x7c00 and make sure BH is set to the page number you want to write to (you want 0) then the following code should work:

[bits 16]          ; 16-Bit code
[org 0x7c00]       ; Set the origin point to 0x7c00

start:
    xor ax,ax      ; We want a segment of 0 for DS for this question
    mov ds,ax      ;     Set AX to appropriate segment value for your situation
    mov es,ax      ; In this case we'll default to ES=DS
    mov bx,0x8000  ; Stack segment can be any usable memory

    mov ss,bx      ; This places it with the top of the stack @ 0x80000.
    mov sp,ax      ; Set SP=0 so the bottom of stack will be @ 0x8FFFF

    cld            ; Set the direction flag to be positive direction

    mov ah, 0x0e
    mov al, [the_secret]  ; al = character from memory DS:[the_secret]
    xor bh, bh            ; bh = 0 = video page number
    int 0x10;

    jmp $

the_secret:;
    db 'X';

times 510-($-$$) db 0
dw 0xAA55

由于我们将原点设置为0x7c00,因此启动代码将 DS 设置为零.引导加载程序的加载地址为0x0000:0x7c00(物理地址0x07c00).这样可以确保正确访问变量the_secret. mov al, [the_secret]等同于说mov al, ds:[the_secret].如果 DS 段寄存器设置不正确,并且原点设置不正确,则无法从正确的位置读取内存访问.

The start up code sets DS to zero since we set an origin point of 0x7c00. The bootloader is loaded at 0x0000:0x7c00 (physical address 0x07c00). This ensures accessing the variable the_secret will be done properly. mov al, [the_secret] is the equivalent of saying mov al, ds:[the_secret]. If the DS segment register is not set properly, and the origin point isn't set properly, the memory access will not read from the proper location.

INT 0x10/AH = 0x0E 要求设置页码.第一个视频显示页面为0,应相应设置 BH .

INT 0x10/AH=0x0E requires a page number to be set. The first video display page is 0, BH should be set accordingly.

有关其他设置说明的更多信息,请参见我的StackOverflow答案,其中包含常规Bootloader提示.

More on the other setup instructions can be found in my StackOverflow answer that contains General Bootloader Tips.

如果正确地写入磁盘映像,我提供的代码应在控制台上显示X.

The code I have presented should display X to the console if properly written to a disk image.

要汇编此代码并生成磁盘映像(在我的示例中为720k软盘):

To assemble this code and produce a disk image (in my example a 720k floppy):

nasm -f bin bootload.asm -o bootload.bin
dd if=/dev/zero of=disk.img bs=1024 count=720
dd if=bootload.bin of=disk.img bs=512 count=1 conv=notrunc

第一个命令将bootload.asm组装到一个名为bootload.bin的平面二进制文件中.第二个命令生成大小为1024 * 720(软盘720kb)的零填充磁盘映像(disk.img),最后一个命令将bootload.bin中的512字节数据复制到磁盘映像的第一个扇区. conv=notrunc告诉 DD 写入后不要截断文件.如果您不选择该选项,则在写入引导扇区后disk.img的长度将为512字节.

The first command does the assembling of bootload.asm into a flat binary file called bootload.bin. The second command produces a zero filled disk image (disk.img) of size 1024 * 720 (720kb floppy), and the last command copies 512 bytes of data from bootload.bin to the first sector of the disk image. conv=notrunc tells DD not to truncate the file after writing. If you were to leave that off disk.img would be 512 bytes long after the bootsector was written.

这篇关于"times 510-($-$$)db 0&";不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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