回 帖 发 新 帖 刷新版面

主题:汇编的数字输出为乱码?

最近编了一个小程序,目的:将ax中的数分成四组,并输出到AL,BL,CL,DL中。要求输出形式为:
the result of the question 5.3:
1 is the num of AL;
2 is the num of BL;
3 is the num of CL;
4 is the num of DL.
可我的这个程序的输出却是:
the result of the question 5.3:
☺ is the num of AL;
☻ is the num of BL;
♥ is the num of CL;
♦ is the num of DL.(其中&#9786等在输出窗口上显示为笑脸和棱形等,不是数字1,2,3,4)
请问各位高手,这是怎么一回事?应该如何改?源程序如下:
;**************************************************
data_seg segment
  a db 'the result of the question 5.3:',0dh,0ah,'$'
  b db ?
  c db ?
  d db ?
  e db ?
  string1 db ' is the num of AL;',0dh,0ah,'$'
  string2 db ' is the num of BL;',0dh,0ah,'$'
  string3 db ' is the num of CL;',0dh,0ah,'$'
  string4 db ' is the num of DL.',0dh,0ah,'$'
data_seg ends
;**************************************************  
code_seg segment
  assume ds:data_seg,cs:code_seg
start:
            mov ax,data_seg
            mov ds,ax
            
            mov dx,offset a   ;output a string
            mov ah,9
            int 21h
            
            mov ax,1234h      ;get the first 4 bit of the num(1234h)
            mov cl,4
      rol ax,cl
      and ax,000fh
      mov b,al
      
      mov ax,1234h      ;get the second 4 bit of the num(1234h)
      mov cl,8
      rol ax,cl
      and ax,000fh
      mov c,al
      
      mov ax,1234h      ;get the third 4 bit of the num(1234h)
      mov cl,0ch
      rol ax,cl
      and ax,000fh
      mov d,al
      
      mov ax,1234h      ;get the last 4 bit of the num(1234h)
      and ax,000fh
      mov e,al
      
      mov ah,2          ;output the fitst 4 bit of the num
      mov dl,b
      int 21h
      mov dx,offset string1
      mov ah,9
      int 21h
      
      mov ah,2          ;output the second 4 bit of the num
      mov dl,c
      int 21h
      mov dx,offset string2
      mov ah,9
      int 21h
      
      mov ah,2          ;output the third 4 bit of the num
      mov dl,d
      int 21h
      mov dx,offset string3
      mov ah,9
      int 21h
      
      mov ah,2          ;output the last 4 bit of the num
      mov dl,e
      int 21h
      mov dx,offset string4
      mov ah,9
      int 21h
      
      mov al,b
      mov bl,c
      mov cl,d
      mov dl,e
      
      mov ah,4ch
      int 21h                                  
code_seg ends      
;**************************************************
   end start                  

回复列表 (共3个回复)

沙发

;**************************************************
data_seg segment
  a db 'the result of the question 5.3:',0dh,0ah,'$'
  b db ?
  c1 db ?
  d db ?
  e db ?
  string1 db ' is the num of AL;',0dh,0ah,'$'
  string2 db ' is the num of BL;',0dh,0ah,'$'
  string3 db ' is the num of CL;',0dh,0ah,'$'
  string4 db ' is the num of DL.',0dh,0ah,'$'
data_seg ends
;**************************************************  
code_seg segment
  assume ds:data_seg,cs:code_seg
start:
            mov ax,data_seg
            mov ds,ax
            
            mov dx,offset a   ;output a string
            mov ah,9
            int 21h
            
            mov ax,1234h      ;get the first 4 bit of the num(1234h)
            mov cl,4
      rol ax,cl
      and ax,000fh
      mov b,al
      
      mov ax,1234h      ;get the second 4 bit of the num(1234h)
      mov cl,8
      rol ax,cl
      and ax,000fh
      mov c1,al
      
      mov ax,1234h      ;get the third 4 bit of the num(1234h)
      mov cl,0ch
      rol ax,cl
      and ax,000fh
      mov d,al
      
      mov ax,1234h      ;get the last 4 bit of the num(1234h)
      and ax,000fh
      mov e,al
      
      mov ah,2          ;output the fitst 4 bit of the num
      mov dl,b
      or dl, '0'        ;转换成 ASCII 码在输出, 这句也可以换成 add dl, '0'
      int 21h
      mov dx,offset string1
      mov ah,9
      int 21h
      
      mov ah,2          ;output the second 4 bit of the num
      mov dl,c1
      or  dl, '0'
      int 21h
      mov dx,offset string2
      mov ah,9
      int 21h
      
      mov ah,2          ;output the third 4 bit of the num
      mov dl,d
      or dl, '0'
      int 21h
      mov dx,offset string3
      mov ah,9
      int 21h
      
      mov ah,2          ;output the last 4 bit of the num
      mov dl,e
      or    dl, '0'
      int 21h
      mov dx,offset string4
      mov ah,9
      int 21h
      
      mov al,b
      mov bl,c1
      mov cl,d
      mov dl,e
      
      mov ah,4ch
      int 21h                                  
code_seg ends      
;**************************************************
   end start

板凳

这里的 c 我改成了 c1,因为汇编器通不过(masm 6.15),可能又和哪个指令或伪指令重名
了。
其他地方我改了一下,已经可以正常运行了。你看看吧

3 楼

字符的ASCII码的问题. 字符'3'等价与程序中的数值30h+3.

我来回复

您尚未登录,请登录后再回复。点此登录或注册