【问题标题】:Boot time program running on virtual computer without OS在没有操作系统的虚拟计算机上运行的启动时间程序
【发布时间】:2014-01-08 13:11:53
【问题描述】:

对于学校作业,我必须编写一个如下所述的程序,我真的很想得到一些关于如何解决这个问题的帮助。明确地说,我不想让你解决这个问题,我只是想要一些关于如何做的指导。

问题:

编写一个启动时间程序,该程序将在没有操作系统的虚拟计算机中运行。程序必须根据 ALT 键的状态打印出您的姓名和“ALT 键被按下”或“ALT 键未被按下”字样。

其他提示: - 程序必须以 16 位模式编写

  • 包含其数据的编译程序的大小必须小于 510 字节

  • 指令“org 0x7c00”指定加载程序的内存中的正确地址

  • 在数据之前写指令

  • 程序应该在无限循环中执行

  • 没有printf函数,你将不得不使用中断0x10

  • 要读取 alt 键的状态,您可以使用中断 0x16

  • 使用中断 0x10 定位文本的输出

  • 可执行文件的二进制格式应为“bin”(nasm -f bin -o boot.bin code.asm)

  • 将二进制文件大小调整为软盘大小(truncate -s 1474560 boot.bin)

  • 将二进制文件标记为可引导磁盘:在位置 0x1FE 保存值 0x55 并在 location 0x1FF 保存值 0xAA(使用十六进制编辑器,例如:ghex2)

  • 用你的二进制文件作为软盘启动虚拟机:(nice -n 19 qemu -fda boot.bin)

【问题讨论】:

  • 到目前为止你尝试过什么?你有什么在工作,你到底卡在哪里?
  • 这里给了你很多提示和指导。剩下的唯一一件事就是继续编写代码。我看不出我们还能提供什么帮助。

标签: nasm


【解决方案1】:

我建议您阅读关于程序集引导加载程序的this。摘自那篇文章,这里是 hello world -

        org 7C00h

        jmp short Start ;Jump over the data (the 'short' keyword makes the jmp instruction smaller)

Msg:    db "Hello World! "
EndMsg:

Start:  mov bx, 000Fh   ;Page 0, colour attribute 15 (white) for the int 10 calls below
        mov cx, 1       ;We will want to write 1 character
        xor dx, dx      ;Start at top left corner
        mov ds, dx      ;Ensure ds = 0 (to let us load the message)
        cld             ;Ensure direction flag is cleared (for LODSB)

Print:  mov si, Msg     ;Loads the address of the first byte of the message, 7C02h in this case

                        ;PC BIOS Interrupt 10 Subfunction 2 - Set cursor position
                        ;AH = 2
Char:   mov ah, 2       ;BH = page, DH = row, DL = column
        int 10h
        lodsb           ;Load a byte of the message into AL.
                        ;Remember that DS is 0 and SI holds the
                        ;offset of one of the bytes of the message.

                        ;PC BIOS Interrupt 10 Subfunction 9 - Write character and colour
                        ;AH = 9
        mov ah, 9       ;BH = page, AL = character, BL = attribute, CX = character count
        int 10h

        inc dl          ;Advance cursor

        cmp dl, 80      ;Wrap around edge of screen if necessary
        jne Skip
        xor dl, dl
        inc dh

        cmp dh, 25      ;Wrap around bottom of screen if necessary
        jne Skip
        xor dh, dh

Skip:   cmp si, EndMsg  ;If we're not at end of message,
        jne Char        ;continue loading characters
        jmp Print       ;otherwise restart from the beginning of the message


times 0200h - 2 - ($ - $$)  db 0    ;Zerofill up to 510 bytes

        dw 0AA55h       ;Boot Sector signature

;OPTIONAL:
;To zerofill up to the size of a standard 1.44MB, 3.5" floppy disk
;times 1474560 - ($ - $$) db 0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 2014-05-11
    • 2014-11-25
    • 1970-01-01
    • 2017-06-10
    相关资源
    最近更新 更多