可以获取 Keypress 并打印它的程序集 OS
Assembly OS that can get a Keypress and print it
基本上我正在做的是构建一个简单的 console-based OS,它在功能上类似于 MS-DOS。我知道像这样的项目不容易维护,我真的不在乎 ;)。所以这是我到目前为止所做的:
;------------------------------------------------------
;| SMOS Shell Source |
;| Kept under GPLv3 Open Source license |
;| (https://www.gnu.org/licenses/gpl.txt) |
;------------------------------------------------------
BITS 16
start:
mov ax, 07C0h
add ax, 288
mov ss, ax
mov sp, 4096
mov ax, 07C0h
mov ds, ax
jmp kool
kool:
mov si, lineone
call print_string
mov si, linetwo
call print_string
mov si, linethree
call print_string
call newline
mov si, shellprompt
call print_string
jmp type
shell:
call newline
mov si, shellprompt
call print_string
jmp type
lineone db '----------------------',13,10,0
linetwo db '| WELCOME TO SMOS |',13,10,0
linethree db '----------------------',13,10,0
shellprompt db 'smos> ',0
break db 13,10,0
clearscreen:
mov ah, 0x06
mov al, 0
int 10h
type:
mov ah,0h
int 16h
jmp shell
print_string:
mov ah, 0Eh
.repeat:
lodsb
cmp al, 0
je done
int 10h
jmp .repeat
newline:
mov si, break
call print_string
done:
ret
times 510-($-$$) db 0
dw 0xAA55
我想要的是一种获取按键并将其打印到 smos>
shell 行的方法。因此,如果用户键入 test
,它将显示 smos> test
,如果用户按回车键,它将能够被存储,然后进行操作。我已经查找了与我的问题类似的任何内容,您可以在 type:
函数中看到它停止进程,直到按下某个键,这是我发现的尝试。但是,我不知道如何继续代码以获得我解释的结果。无论如何,请记住当您回答我是装配新手时,所以在解释事情时请像 5-year-old 一样对待我。提前致谢!
你的问题太宽泛,无法回答,但我可以解决你目前似乎遇到的问题:
That is the problem, I don't know how to save it to register. I would like to be able to save it like myvar db, al,0. al being the keystroke stored from int 16h. – DecstarG 4 hours ago
诀窍是将击键保存在内存中。
首先你必须保留一块内存,你可以为此使用堆栈(参见:What is stack frame in assembly?), or use a memory manager (See here: https://github.com/jakubbogucki/memoryManager), Or just use a fixed buffer in memory (see: 3.2.2 RESB and Friends: Declaring Uninitialized Data) 仅用于此。
密切关注 buffer overflows,您必须进行检查以确保您没有读取和写入超过缓冲区的末尾。
在内存中存储东西很简单:
keybuffer: resb 1024
endofbuffer: resb 1
mov si,keybuffer ;get the keybuffer address
loop:
.... ;get the keystroke somehow.
mov [si],al ;Store the keystroke (assuming it's in AL
inc si ;Go to the next space in the buffer
mov di,endofbuffer ;Is the buffer full?
cmp di,si ;
je BufferIsFull ;yes, jump to the code to handle this.
jmp loop ;we're still good, keep reading keys.
如果您想看看其他人从头开始编写 OS 的尝试,请查看:http://mikeos.sourceforge.net/write-your-own-os.html
基本上我正在做的是构建一个简单的 console-based OS,它在功能上类似于 MS-DOS。我知道像这样的项目不容易维护,我真的不在乎 ;)。所以这是我到目前为止所做的:
;------------------------------------------------------
;| SMOS Shell Source |
;| Kept under GPLv3 Open Source license |
;| (https://www.gnu.org/licenses/gpl.txt) |
;------------------------------------------------------
BITS 16
start:
mov ax, 07C0h
add ax, 288
mov ss, ax
mov sp, 4096
mov ax, 07C0h
mov ds, ax
jmp kool
kool:
mov si, lineone
call print_string
mov si, linetwo
call print_string
mov si, linethree
call print_string
call newline
mov si, shellprompt
call print_string
jmp type
shell:
call newline
mov si, shellprompt
call print_string
jmp type
lineone db '----------------------',13,10,0
linetwo db '| WELCOME TO SMOS |',13,10,0
linethree db '----------------------',13,10,0
shellprompt db 'smos> ',0
break db 13,10,0
clearscreen:
mov ah, 0x06
mov al, 0
int 10h
type:
mov ah,0h
int 16h
jmp shell
print_string:
mov ah, 0Eh
.repeat:
lodsb
cmp al, 0
je done
int 10h
jmp .repeat
newline:
mov si, break
call print_string
done:
ret
times 510-($-$$) db 0
dw 0xAA55
我想要的是一种获取按键并将其打印到 smos>
shell 行的方法。因此,如果用户键入 test
,它将显示 smos> test
,如果用户按回车键,它将能够被存储,然后进行操作。我已经查找了与我的问题类似的任何内容,您可以在 type:
函数中看到它停止进程,直到按下某个键,这是我发现的尝试。但是,我不知道如何继续代码以获得我解释的结果。无论如何,请记住当您回答我是装配新手时,所以在解释事情时请像 5-year-old 一样对待我。提前致谢!
你的问题太宽泛,无法回答,但我可以解决你目前似乎遇到的问题:
That is the problem, I don't know how to save it to register. I would like to be able to save it like myvar db, al,0. al being the keystroke stored from int 16h. – DecstarG 4 hours ago
诀窍是将击键保存在内存中。
首先你必须保留一块内存,你可以为此使用堆栈(参见:What is stack frame in assembly?), or use a memory manager (See here: https://github.com/jakubbogucki/memoryManager), Or just use a fixed buffer in memory (see: 3.2.2 RESB and Friends: Declaring Uninitialized Data) 仅用于此。
密切关注 buffer overflows,您必须进行检查以确保您没有读取和写入超过缓冲区的末尾。
在内存中存储东西很简单:
keybuffer: resb 1024
endofbuffer: resb 1
mov si,keybuffer ;get the keybuffer address
loop:
.... ;get the keystroke somehow.
mov [si],al ;Store the keystroke (assuming it's in AL
inc si ;Go to the next space in the buffer
mov di,endofbuffer ;Is the buffer full?
cmp di,si ;
je BufferIsFull ;yes, jump to the code to handle this.
jmp loop ;we're still good, keep reading keys.
如果您想看看其他人从头开始编写 OS 的尝试,请查看:http://mikeos.sourceforge.net/write-your-own-os.html