如何在汇编中临时存储一行中的值?
题
我正在制作一个 16 位实模式操作系统,我想传递用户输入的命令。我可以进行输入,但我不确定如何存储结果字符串以便以后可以对其进行解析。有没有比将每个字符放入堆栈然后在需要使用时弹出并反转它们更好的方法?
我的主循环:
mainLoop:
mov bx, s_PROMPT
call printStr ; print the 'MOOS> ' prompt
inputLoop:
call getKeyPress ; wait for the user to press a key
call printChar ; print the pressed key so the user can
; see what they've typed
push bl???
cmp bl, 0xD ; 0xD = 13 = ASCII code for enter
jne inputLoop ; go to inputLoop if does not equal enter
call newLine
jmp mainLoop
该操作系统称为 莫斯 顺便一提。
感谢任何能提供帮助的人。
解决方案
每次推送后你的堆栈看起来像这样:
00: 's' - Assume that here starts your string by pusing each char
01: 't'
02: 'r'
03: 'i'
04: 'n'
05: 'g'
06: - Here is your stackpointer after the string has been completed.
所以你只需将当前的堆栈指针存储在某个地方(这里是 0)。要么在使用字符时计算长度,要么从保存的值中减去当前堆栈以获得长度,然后将其复制到某个地方。您可能需要添加 0 字节或将长度与字符串一起存储,具体取决于字符串的组织方式。当然你也可以直接使用字符串,不需要复制它。
完成后,只需将堆栈指针重置为原始值即可 0
你就完成了。
不隶属于 StackOverflow