emu8086 - 如何从ASCII码获取CHAR

时间:2017-05-31 08:57:16

标签: assembly emu8086

我想打印字符串'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

1 个答案:

答案 0 :(得分:3)

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
相关问题