ADD al,"0"有什么作用?为什么在打印整数之前使用它? [英] What does ADD al, '0' do, and why use it before printing an integer digit?
问题描述
我是汇编语言编程的新手
我搜索了二进制搜索程序,并找到了它,然后尝试理解该程序.它工作正常,但我无法理解代码的成功部分:
I am a novice in assembly language programming
I searched for binary search program and found this and I tried understand the program. It's working fine but I couldn't understand the success part of the code:
什么是ADD al,'0'
,什么是mov res,al
?
.model small
.stack 100h
.data
ARR DW 1000H,2000H,3000H,4000H,5000H,6000H
LEN DW ($-ARR)/2
KEY EQU 2000H
SUC DB "KEY IS FOUND AT$"
FAILURE DB "KEY IS NOT FOUND$"
RES DB "POSITION",13,10,"$"
.CODE
START:
MOV AX,@data
MOV DS,AX
MOV BX,00 ;LOW
MOV DX,LEN ;HIGH
MOV CX,KEY ;KEY
AGAIN:
CMP BX,DX
JA FAIL
MOV AX,BX
ADD AX,DX
SHR AX,1
MOV SI,AX
ADD SI,SI
CMP CX,ARR[SI]
JAE BIG
DEC AX
MOV DX,AX
JMP AGAIN
BIG:
JE SUCCESS
INC AX
MOV BX,AX
JMP AGAIN
SUCCESS:
ADD AL,01
ADD AL,'0'
MOV RES,AL
LEA DX SUC
JMP DISP
FAIL:
LEA DX,FAILURE
DISP:
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
END START
推荐答案
add al, '0'
将一些1位数字转换为相应的ASCII码,以便在成功时将其作为结果值显示在屏幕上.
add al, '0'
converts some 1 digit number to the corresponding ASCII code in order to display it at the screen as a result value on success.
mov res, al
将寄存器AL的值存储在变量RES的第一个字节中.只要RES指向字符串'POSITION',13,10,'$'
,AL的值将存储在该字符串的字符'P'的顶部,并且如果例如AL = 33h,则该字符串变为'3OSITION',13,10,'$'
.
mov res, al
stores the value of the register AL in the first byte of the variable RES. As long as RES points to a string 'POSITION',13,10,'$'
, the value of AL will be stored on top of the character 'P' of this string and if, for example AL=33h, the string becomes '3OSITION',13,10,'$'
.
这篇关于ADD al,"0"有什么作用?为什么在打印整数之前使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!