[英]emu8086 - How to get CHAR from ASCII code
我想打印字符串'Hello World'的长度,我得到的值(0Bh是11,但中断是打印ascii字符,它是♂而不是11)
org 100h
LEA SI, msg
MOV CL, 0
CALL printo
printo PROC
next_char:
CMP b.[SI],0
JE stop
MOV AL,[SI]
MOV AH, 0Eh
INT 10h
INC SI
INC CL
JMP next_char
printo ENDP
stop:
MOV AL,CL ; CL is 0B (11 characters from 'Hello World')
MOV AH, 0Eh
INT 10h ; but it's printing a symbol which has a ascii code of 0B
ret
msg db 'Hello World',0
END
MOV AL,CL ; CL is 0B (11 characters from 'Hello World')
使用AL
的长度,可以很容易地用十进制表示法表示它。
AAM
指令首先将AL
寄存器除以10,然后将商保留在AH
,其余部分保留在AL
。
请注意,此解决方案适用于0到99之间的所有长度。
aam
add ax, "00" ;Turn into text characters
push ax
mov al, ah
mov ah, 0Eh ;Display tenths
int 10h
pop ax
mov ah, 0Eh ;Display units
int 10h
如果涉及的数量小于10,实际上在单个数字前面显示零是很难看的。 然后只需添加代码旁边的代码:
aam
add ax, "00" ;Turn into text characters
cmp ah, "0"
je Skip
push ax
mov al, ah
mov ah, 0Eh ;Display tenths
int 10h
pop ax
Skip:
mov ah, 0Eh ;Display units
int 10h
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.