emu8086 - 如何从 ASCII 码中获取 CHAR

emu8086 - How to get CHAR from ASCII code

我想打印字符串的长度 'Hello World',我正在获取值(0Bh 是 11,但中断打印的是 ♂ 而不是 11 的 ascii 字符)

    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