如何打印存储在AL中的数字,而不是字符? (部件)

时间:2014-04-14 01:20:24

标签: assembly masm x86-16

我有这个程序,它总结了一个数组的正数...但是我在打印结果时遇到了问题。在我的程序中,结果是37,但是当我执行它时,它打印一个%,相当于37个十进制,或25h ......我只想要它打印37 .. 这是我的代码:

 DATOS SEGMENT ; 
 ARRAY DB -1,-2,3,4,5,-6,7,8,-9,10  ;SUMA=37
 COUNTER DW 10
 DATOS ENDS

SEGSTACK SEGMENT STACK
DW 256 DUP (?)
SEGSTACK ENDS

CODIGO SEGMENT
SUMA PROC FAR
    ASSUME CS:CODIGO, DS:DATOS, SS:SEGSTACK
    PUSH DS
    XOR AX, AX
    PUSH AX 
    MOV AX, DATOS
    MOV DS, AX


 MOV AL, 00H
 MOV SI, 00H
 MOV CX, COUNTER

 TAE: CMP ARRAY[SI],00H

 JL MAO
 ADD AL,ARRAY[SI]

 MAO: INC SI 

 LOOP TAE


 ;////////////// P R I N T I N G 
 mov DL,AL
 mov ah,02h
 int 21h
 ;//////////////
 RET
 SUMA ENDP
 CODIGO ENDS
 END SUMA

1 个答案:

答案 0 :(得分:0)

我解决了问题:D

DATOS SEGMENT ; 
ARRAY DB -1,-2,3,4,5,-6,7,8,-9,10  ;SUMA=37
CONTADOR DW 10
LET DB 10,13,"PROGRAMA QUE SUMA ELEMENTOS POSITIVOS DE UN VECTOR: $"
NUMM DB 10,13,"NUMEROS -1,-2,3,4,5,-6,7,8,-9,10  $"
SUM DB 10,13,'EL RESULTADO ES:  $'
DATOS ENDS

SEGSTACK SEGMENT STACK
DW 256 DUP (?)
SEGSTACK ENDS

CODIGO SEGMENT

    SUMA PROC FAR
    ASSUME CS:CODIGO, DS:DATOS, SS:SEGSTACK
    PUSH DS
    XOR AX, AX
    PUSH AX 
    MOV AX, DATOS
    MOV DS, AX

LEA DX, LET
MOV AH,09H
INT 21H

LEA DX, NUMM
MOV AH,09H
INT 21H

LEA DX, SUM
MOV AH,09H
INT 21H

MOV AL, 00H
MOV SI, 00H
MOV CX, CONTADOR

TAE: CMP ARRAY[SI],00H

JL MAO
ADD AL,ARRAY[SI]
MAO: INC SI 

LOOP TAE



MOV AH, 0 
MOV BL, 10  
DIV BL 
MOV CL, AL  
MOV CH, AH  
ADD AL, 48  
MOV AH, 2 
MOV DL, AL  
INT 21h
ADD CH, 48  
MOV DL, CH  
INT 21h
MOV AH, 4Ch        
INT 21h

 RET
 SUMA ENDP
 CODIGO ENDS
 END SUMA