使用 c 中的汇编代码接受并显示 1 到 9 中的一个字符
Accepts and displays one character of 1 through 9 using assembly code in c
谁能解释一下这段汇编代码的每一行?
void main(void){
_asm{
mov ah,8 ;read key no echo
int 21h
cmp al,‘0’ ;filter key code
jb big
cmp al,‘9’
ja big
mov dl,al ;echo 0 – 9
mov ah,2
int 21h
big:
}
}
PS:我是 c/c++ 中的新手。
根据 docs,return 值在 al
中,而不是 ah
。这就是它与 al.
相比的原因
编辑:添加更多细节:
查看这段代码:
mov ah,8 ;read key no echo
int 21h
将其视为函数调用。现在通常 asm 中的函数调用看起来像 call myroutine
。但是 DOS 使用中断来允许您调用各种操作系统功能(从键盘读取键,从文件读取数据等)。
所以,执行调用操作系统的int 21h
指令。但是操作系统应该如何知道 哪个 OS 您想要的功能?通常通过在 ah
中放置一个值。如果进行搜索,您可以找到许多显示所有 int 21h
函数(如 this)列表的资源。右边的数字是你在 ah
.
中输入的值
因此,mov ah,8
正准备调用 "Wait for console input without echo" 函数。 mov ah,2
is "Display output." 其他寄存器用于传递各种参数给被调用的函数。您需要阅读特定中断的描述以了解发生了什么。
注意 NONE 与 "writing inline asm in C." 有关 这就是如何从 DOS 下的 C 代码 运行 调用 OS 函数。如果你不在 DOS 下 运行,int 21
将无法工作。
谁能解释一下这段汇编代码的每一行?
void main(void){
_asm{
mov ah,8 ;read key no echo
int 21h
cmp al,‘0’ ;filter key code
jb big
cmp al,‘9’
ja big
mov dl,al ;echo 0 – 9
mov ah,2
int 21h
big:
}
}
PS:我是 c/c++ 中的新手。
根据 docs,return 值在 al
中,而不是 ah
。这就是它与 al.
编辑:添加更多细节:
查看这段代码:
mov ah,8 ;read key no echo
int 21h
将其视为函数调用。现在通常 asm 中的函数调用看起来像 call myroutine
。但是 DOS 使用中断来允许您调用各种操作系统功能(从键盘读取键,从文件读取数据等)。
所以,执行调用操作系统的int 21h
指令。但是操作系统应该如何知道 哪个 OS 您想要的功能?通常通过在 ah
中放置一个值。如果进行搜索,您可以找到许多显示所有 int 21h
函数(如 this)列表的资源。右边的数字是你在 ah
.
因此,mov ah,8
正准备调用 "Wait for console input without echo" 函数。 mov ah,2
is "Display output." 其他寄存器用于传递各种参数给被调用的函数。您需要阅读特定中断的描述以了解发生了什么。
注意 NONE 与 "writing inline asm in C." 有关 这就是如何从 DOS 下的 C 代码 运行 调用 OS 函数。如果你不在 DOS 下 运行,int 21
将无法工作。