我正在编写一个基于OSDev Wiki和一些相关书籍的信息的操作系统.我发现在跳转到保护模式后,段初始化例程没有正确执行.这是我的第二阶段加载器和内核代码:
; stage2
; still -f bin
[org 0xd200] ; calculated by first stage loader
; GDTs are defined here
jmp entry
GDT_DESC_START:
GDT0:
dw 0 ; Limit 0~15
dw 0 ; Base 0~15
db 0 ; Base 16~23
db 0 ; Access Byte
db 0 ; Limit 16~19 + Flags
db 0 ; Base 24~31
DESCRIPTOR_CODE:
dw 0xffff ; Limit 0~15
CODE_BASE_AX dw 0 ; Base 0~15
CODE_BASE_EAHL db 0 ; Base 16~23
db 0x9a ; …Run Code Online (Sandbox Code Playgroud) I am having troubles with the CMP instruction when comparing single words (2 bytes).
The following is my main.asm:
[org 0x7c00]
mov bx, HELLO_MSG
call print_string
mov bx, GOODBYE_MSG
call print_string
jmp $
%include "print_string.asm"
; Data
HELLO_MSG:
db 'Hello, World!', 0
GOODBYE_MSG:
db 'Goodbye!', 0
Run Code Online (Sandbox Code Playgroud)
This is the print_string.asm file:
print_string:
pusha
mov ah, 0x0e
loop:
call print_char
cmp word [bx], 0
jne loop
popa
ret
print_char:
mov al, [bx]
int 0x10
add bx, 1
ret
Run Code Online (Sandbox Code Playgroud)
This code …
我正在开发一个基本的引导加载程序,它通过 BIOSINT 13h AH=02h中断将辅助引导加载程序读入内存。我已经在模拟器(Virtualbox、Qemu 和 Bochs)中运行了它。
随后,我在我的引导加载程序中添加了一个 BPB(BIOS 参数块),制作了一个可引导的 USB,并在我的真机上使用 USB Floppy Emulation(我在真机 BIOS 的配置屏幕中设置)进行了测试。它就像一个魅力。
在我自己的机器上测试引导加载程序后,我在另一台较新的机器上测试了它。这台新计算机的 BIOS 配置中没有软盘仿真选项,因此无法从 USB 驱动器启动。因此,在这个osdev wikipage 之后,我在 MBR 的末尾添加了一个分区表,以便较新的机器可以从 USB 启动。
使用添加的分区表代码,引导加载程序无法将辅助引导加载程序加载到内存中,并且 BIOSINT 13h失败。我不知道为什么会发生这种情况,因为我没有更改任何实际的引导加载程序代码。我刚刚添加了 64 位 MBR 分区表,将数据读入内存立即失败。
bits 16
org 0x7C00
jmp start
nop
;------------------------------------------;
; Standard BIOS Parameter Block, "BPB". ;
;------------------------------------------;
bpbOEM db 'MSDOS5.0'
bpbSectSize dw 512
bpbClustSize db 1
bpbReservedSe dw 1
bpbFats db 2
bpbRootSize dw 224
bpbTotalSect dw 2880 …Run Code Online (Sandbox Code Playgroud) 我正在用汇编语言开发一个操作系统。\n在某个时间我从 NASM 收到此错误:
\n\n\n\n\nos.asm:113: 错误: TIMES 值 -138 为负数
\n
我想把这个项目进行到底。只有这样的错误才让我绝望!
\n\n这是代码:
\n\nBITS 16\n\nstart:\n mov ax, 07C0h ; Set up 4K stack space after this bootloader\n add ax, 288 ; (4096 + 512) / 16 bytes per paragraph\n mov ss, ax\n mov sp, 4096\n mov ax, 07C0h ; Set data segment to where we're loaded\n mov ds, ax\n call cls\n MOV AH, 06h ; Scroll up function\n XOR AL, AL ; Clear entire screen\n XOR …Run Code Online (Sandbox Code Playgroud) [org 0x7c00]
mov bp, 0x8000 ; set the stack safely away from us
mov sp, bp
mov bx, 0x9000 ; es:bx = 0x0000:0x9000 = 0x09000
Run Code Online (Sandbox Code Playgroud)
正如你可以在注释中看到它说:es:bx = 0x0000:0x9000 = 0x09000。寄存器ES和BX之间有什么关系?该代码仅设置寄存器BX,但注释显示寄存器ES也被设置?
在我努力创建一个简单的独立程序的过程中,我在第一个扇区中编写了一个简单的引导加载程序。它的目的是将程序加载到内存中。为此,我使用了 AH=2 的 INT 13h。代码是:
disk_load:
push dx ; Store DX on stack so later we can recall how many sectors were requested to be read,
; even if it is altered in the meantime.
mov ah, 0x02 ; BIOS read sector.
mov al, dh ; Read DH sectors.
mov ch, 0x00 ; Select cylinder 0.
mov dh, 0x00 ; Select head 0.
mov cl, 0x02 ; Start reading from second sector (i.e. after the boot sector).
int 0x13 …Run Code Online (Sandbox Code Playgroud) 我有一个简单的程序,它将一些以空结尾的字符串移动到寄存器bx:
[org 0x7c00] ; Tells the assembler where the code will be loaded
mov ah, 0x0e
mov bx, HELLO_MSG ; Moves string inside of HELLO_MSG to bx
call print_string ; Calls the print_string function inside of ./print_string.asm
mov bx, GOODBYE_MSG ; Moves string inside of GOODBYE_MSG to bx
call print_string
jmp $ ; Hangs
%include "print_string.asm"
HELLO_MSG:
db 'Hello, World!', 0
GOODBYE_MSG:
db 'Goodbye!', 0
times 510-($-$$) db 0
dw 0xaa55
Run Code Online (Sandbox Code Playgroud)
和一个print_string内部函数./print_string.asm:
print_string:
mov …Run Code Online (Sandbox Code Playgroud) 编写在QEMU中作为引导加载程序运行的x86实模式汇编程序时遇到问题.我正在尝试通过BIOS中断0x10打印文本.我的代码是:
print:
pusha
.loop:
mov AL, [SI]
cmp AL, 0
je .end
call printChar
inc SI
jmp .loop
.end:
popa
ret
printChar:
pusha
mov AH, 0x0E
mov BH, 0
mov BL, 0x0F
int 0x10
popa
ret
Run Code Online (Sandbox Code Playgroud)
我[ORG 0x7c00]用作原点.我测试了printChar标签,并在AL中用一些字母调用它,它工作正常.当我尝试将内存地址加载到这样的消息时:
loadMsg db "Loading",0
mov SI, loadMessage
call print
Run Code Online (Sandbox Code Playgroud)
我在QEMU仿真器上输出像'U'这样的垃圾作为输出.昨天,我编写了一个与此类似的代码,完全没有问题.是什么导致了我的问题以及如何解决?
我正在尝试学习汇编并编写引导程序.以下代码将软盘驱动器的内容加载到内存并跳转到它(开始在地址0x1000加载).此代码应该在屏幕上打印"X",但由于某种原因,它会打印一个空格.有人可以告诉我有什么问题吗?
[bits 16]
jmp reset
reset: ;Resets floppy drive
xor ax,ax ;0 = Reset floppy disk
mov dl,0 ;Drive 0 is floppy
int 0x13
jc reset ;If carry flag was set, try again
mov ax,0x1000 ;When we read the sector, we are going to read address 0x1000
mov es,ax ;Set ES with 0x1000
floppy:
mov ah,0x2 ;2 = Read floppy
mov al,0x11 ;Reading one sector
mov ch,0x0 ;Track 1
mov cl,0x2 ;Sector 2, track 1
mov dh,0x0 ;Head 1
mov …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习操作系统的工作方式。这是我要解决的一个容易的任务:编写一个简单的引导程序,提示用户输入他的名字并打印欢迎消息,例如“ hello,>> name <<”-之后,它什么也不做。
如果minix 3与qemu此相关,我正在与一起运行。我只是将asm文件dd及其前512个字节编译为/dev/c0d0(的虚拟硬盘minix)。
我可以打印消息并打印用户输入的内容。但是,此后我没有设法打印用户名。
这是我的汇编代码:
[bits 16]
[org 0x7c00]
mov si, HelloString
call print_string
mov di, name
call read_name
mov si, name
call print_string
read_name:
read_char:
mov ah, 0h ; read character from keyboard
mov [di], ah ; save it in the buffer
inc di ; next char
int 0x16 ; store it in AL
cmp ah, 0x0d ; check for enter
je stop_reading
mov …Run Code Online (Sandbox Code Playgroud)