我想用16位汇编制作一个小型操作系统。 在这段代码中,我创建了一种“终端”,在其中获取用户输入,如果输入被关闭,则启动函数来关闭所有内容,否则什么也不会发生,循环将恢复(现在,稍后我将创建其他功能,因此如果命令不是“关闭”,那么其他检查将开始查看它是否是另一个命令)
代码:
bits 16
section .kernel
global _start_kernel
_start_kernel:
mov ax, 0x3
int 10h
commandLoop:
mov si, user
call print
mov di, input_string
call input
mov si, input_string
call print
ifCommandShutdown:
cld
mov si, C_shutdown
mov di, input_string
mov cx, CL_shutdown
cmpsb
jz thenCommandShutdown
elseCommandShutdown:
call newLine
jmp commandLoop
thenCommandShutdown:
call shutdown
exit:
cli
hlt
%include "lib/console.asm"
%include "lib/system.asm"
user: db "user >> ", 0
input_string:
;- Commands Variables ------------------------------+
; |
C_shutdown: db "shutdown", 0 ; |
C_reboot: db "reboot" , 0 ; |
; |
CL_shutdown: db $ - C_shutdown ; |
CL_reboot: db $ - C_reboot ; |
; |
;---------------------------------------------------+
times 512-($-$$) db 0
控制台.asm:
print:
mov ah, 0x0e
characterLoop:
lodsb
or al, al
jz break
int 10h
jmp characterLoop
break:
ret
input:
mov ah, 0x0
int 16h
ifKeyIsEnter:
cmp al, 0x0D
jz enterIsPressed
elseEnterKey:
stosb
mov ah, 0x0e
int 10h
jmp input
enterIsPressed:
mov al, 0x0
stosb
call newLine
ret
newLine:
mov ah, 0x0e
mov al, 13
int 10h
mov al, 10
int 10h
ret
系统.asm:
shutdown:
mov ax, 0x1000
mov ax, ss
mov sp, 0xf000
mov ax, 0x5307
mov bx, 0x0001
mov cx, 0x0003
int 0x15
我编译时没有错误,但在 qemu 中它总是关闭