【问题标题】:Booting the disk partitions引导磁盘分区
【发布时间】:2015-01-05 18:33:47
【问题描述】:

我有这个任务来制作显示我的电脑上的分区磁盘的引导程序.. 我进行了很多搜索,发现将这些信息保存在 1BE 中的部分,所以我试图从那个扇区读取..我找到了一些代码并试图研究中断 13 这段代码,但我不知道我觉得有什么东西错了

然后当我使用 NASM 运行它时 它显示错误无法识别指令 ORG

非常感谢 :) :) :)

[BITS 16]                            ; 16 bit code generation
[ORG 0x7C00]                          ; Origin location

; Main program
main:                         ; Label for the start of the main program


start: 
       mov ax,cs
       mov ds,ax
       mov es,ax
       mov ss,ax
       sti

reset: mov ah,0h                  ;resetting the drive to the first sector
       mov dl, 0x80
       int 13h
       js reset

read:  mov ax,1BEh              ;reading sectors into memory address 0x1BE:0
       mov es,ax
       xor bx,bx
       mov ah,02h
       mov al,01h               ;reading 1 sector
       mov  cx, 0001h           ; track 0, sector 1
       mov  dx, 0000h           ; head 0, drive 0
       int 13h

      jc   errp                ; detect error
      ret




          jmp $            ; Never ending loop

; Procedures
errp:                          ; process error here
 mov ax,0x0000          
 mov ds,ax  
 mov si, ERRR                 ; Load the string into position for the procedure.
 call PutStr



PutStr:     ; Procedure label/start
                ; Set up the registers for the interrupt call
 mov ah,0x0E    ; The function to display a chacter (teletype)
 mov bh,0x00    ; Page number
 mov bl,0x07    ; Normal text attribute

.nextchar   
 lodsb  

 or al,al           
 jz .return         
 int 0x10   ; Run the BIOS video interrupt 

 jmp .nextchar  ; Loop back round tothe top
.return     ; Label at the end to jump to when complete
 ret        ; Return to main program

; Data

ERRR db 'ERROOOORR',13,10,0

; End Matter
times 510-($-$$) db 0   
dw 0xAA55       

【问题讨论】:

  • “我的电脑”是某种模拟计算机系统吗?
  • 查看 nasm 手册,ORG 指令不应该有 '[' 和 ']'。
  • 看来你没有和-f bin 组装(另一种方式是错误的!)。
  • @CraigAnderson:带括号的原始形式没有错。 From the manual:“NASM 的指令有两种类型:用户级指令和原始指令。通常,每个指令都有用户级形式和原始形式。在几乎所有情况下,我们建议用户使用用户级形式指令,它们被实现为调用原始形式的宏。原始指令用方括号括起来;用户级指令不是。"
  • @rkhb 我在看这个(nasm.us/doc/nasmdoc7.html#section-7.1.1)。该部分是否具有误导性?

标签: assembly nasm boot bios sector


【解决方案1】:

您使用 ORG 0x7C00 的事实意味着您将段寄存器设置为零,而不是 CS 中已有的值。
用于重置驱动器的 BIOS 函数不会在符号标志 SF 中返回任何内容。然而,它确实改变了进位标志 CF。
分区表位于引导扇区的偏移量 0x01BE 处,包含 4 个 16 字节的条目。
您的(当前未使用的)READ 函数可以在内存中的任何位置使用扇区大小的缓冲区,但我建议远离 0x7C00 处的 512 个字节。
您是否注意到您正在重置第一个硬盘,但您正在从第一个软盘读取?
我想你的意思是在call PutStr 之后写jmp $ ; Never ending loop 不是吗?
如果练习是关于显示可用的分区,那么您所要做的就是显示每个分区表条目中的 CHS 值,当然除非系统指示符字节读取 0 表示没有分区。

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 2011-01-09
    • 1970-01-01
    • 2013-10-11
    • 2019-12-18
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多