mov ax,4c00h int 21h和mov ax,4ch int 21h区别
时间: 2023-12-27 08:03:50 浏览: 90
这两条指令都是用来终止程序的。但是,它们的功能是不同的。
第一条指令 mov ax,4c00h ; int 21h 是用来正常终止程序的,它会返回一个退出码给操作系统。通常情况下,退出码是 0,表示程序正常结束。但是,也可以根据需要设置其他的退出码。
第二条指令 mov ax,4ch ; int 21h 则是用来非正常终止程序的。它不会返回退出码给操作系统,而是直接退出程序。通常情况下,这个退出方式并不被推荐使用,因为它可能会导致程序结束时没有释放资源或清理状态,从而对系统造成影响。
相关问题
mov ah, 08h int 21h mov ax, 4C00h int 21h
These are assembly language instructions for the 16-bit Intel x86 architecture.
The first line moves the hexadecimal value 08h into the AH register.
The second line calls the DOS interrupt 21h, which is used for various system services in MS-DOS. In this case, it likely performs a read operation from standard input (keyboard).
The third line moves the hexadecimal value 4C00h into the AX register.
The fourth line calls the DOS interrupt 21h again, but this time with function code 4Ch, which terminates the program and returns control to the operating system.
Overall, this code likely reads a single character from the keyboard and then terminates the program.
stack segment stack ends data segment string_1 db 'please input a num: $' string_2 db 0ah,0dh,'the result is : $' result db 0,0 data ends code segment assume cs:code,ds:data,ss:stack start: mov ax,data mov ds,ax lea dx,string_1 mov ah,09h int 21h mov ah,01h int 21h sub al,30h mov cx,2 mov si,offset result+1 mov ah,0 mov bl,10 cmp al,10 jb shuzi sub al,27h shuzi: div bl mov [si],ah dec si mov ah,0 loop shuzi mov si,offset result mov cx,2 lea dx,string_2 mov ah,09h int 21h shuchu: mov dl,[si] add dl,30h mov ah,02h int 21h inc si loop shuchu mov ax,4c00h int 21h code ends end start 每句解释
这是一段汇编语言代码,实现了一个简单的输入数字并输出结果的程序。下面是每句代码的解释:
```
stack segment stack ends
```
定义了栈段。
```
data segment
string_1 db 'please input a num: $'
string_2 db 0ah,0dh,'the result is : $'
result db 0,0
data ends
```
定义了数据段,包括两个字符串和一个用于存储结果的变量。
```
code segment
assume cs:code,ds:data,ss:stack
start:
```
定义了代码段,并将代码段、数据段和栈段进行了关联。
```
mov ax,data
mov ds,ax
```
将数据段的地址存入 AX 寄存器,并将其传递给 DS 寄存器,以便访问数据段。
```
lea dx,string_1
mov ah,09h
int 21h
```
将字符串 string_1 的地址存入 DX 寄存器,调用 DOS 中断 21h 的 09h 功能,将字符串输出到屏幕上。
```
mov ah,01h
int 21h
sub al,30h
```
调用 DOS 中断 21h 的 01h 功能,等待用户输入一个字符,并将其存入 AL 寄存器中。由于用户输入的是 ASCII 码,需要将其转换成数字。将 '0' 的 ASCII 码(30h)减去 AL 中的值即可。
```
mov cx,2
mov si,offset result+1
mov ah,0
mov bl,10
cmp al,10
jb shuzi
sub al,27h
shuzi:
div bl
mov [si],ah
dec si
mov ah,0
loop shuzi
```
将 AL 寄存器中的数字进行分离,并存储到 result 变量中。首先将 CX 寄存器设置为 2,表示需要分离两位数字。将 SI 寄存器设置为 result 变量的第二个字节的地址,以便存储数字。将 BL 寄存器设置为 10,便于进行除法运算。如果用户输入的数字小于 10,直接跳转到 shuzi 标签下的代码。否则,将 AL 寄存器中的值减去 27h,得到对应的数字,并进行除法运算,将商存储到 SI 指向的地址中,将 SI 寄存器减 1,重复该操作直到 CX 寄存器为 0。
```
mov si,offset result
mov cx,2
lea dx,string_2
mov ah,09h
int 21h
shuchu:
mov dl,[si]
add dl,30h
mov ah,02h
int 21h
inc si
loop shuchu
```
将 result 变量中的数字转换成字符串,并输出到屏幕上。首先将 SI 寄存器设置为 result 变量的第一个字节的地址。将 CX 寄存器设置为 2,表示需要输出两个数字。将字符串 string_2 的地址存入 DX 寄存器,调用 DOS 中断 21h 的 09h 功能,将字符串输出到屏幕上。将 DL 寄存器设置为 SI 指向的地址中的值,并加上 30h,得到对应的 ASCII 码。将该值输出到屏幕上,并将 SI 寄存器加 1,重复该操作直到 CX 寄存器为 0。
```
mov ax,4c00h
int 21h
```
结束程序。将 4c00h 存入 AX 寄存器,调用 DOS 中断 21h 的 4Ch 功能,退出程序。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)