0

我知道如何输出一个字符串。如何输出一个数字?我正在使用 Windows assembler 6.11 进行 MS DOS 编译

这是我尝试过的。但它打印垃圾

我根据以下评论编辑了我的代码。

[编辑]

DATA SEGMENT
NUM1 DW 0001H
NUM2 DW 0002H
SUM DW 2 DUP(0)
RESULT DW ?
 DATA ENDS

 CODE SEGMENT
 ASSUME CS:CODE,DS:DATA
 START: MOV AX,DATA
MOV DS,AX

MOV CX,00H
MOV AX,NUM1
ADD AX,NUM2
JNC DISPLAY

INC CX
MOV SUM+2,CX

 DISPLAY:
MOV SI,RESULT
ADD SI,9
MOV AX,0
MOV [SI],AX
MOV BX,10

 LOOP1:
XOR DX,DX
DIV BX
ADD DL,'0'
DEC SI
MOV [SI],DL
TEST AX,AX
JNZ LOOP1
MOV AX,SI
LEA SI,RESULT

MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H

 CODE ENDS
END START
4

1 回答 1

0
DATA SEGMENT
NUM1 WORD 000AH
NUM2 WORD 000BH
SUM DW 2 DUP(0)
RESULT DB '        $'
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:  MOV AX,DATA
MOV DS,AX

;-----begin addition-----------------
MOV CX,0000H
MOV AX,NUM1
ADD AX,NUM2
MOV SUM,AX
JNC DISPLAY

INC CX
MOV SUM+2,CX
;------Display on screen------------
DISPLAY:
LEA DI,RESULT
ADD DI,0007H
MOV AX,SUM
MOV BX,000AH    ;BX=10 used as a constatnt in the following loop
LOOP1:
XOR DX,DX
DIV BX      ;quotient in AX remainder in DX
ADD DX,0030H

DEC DI
MOV [DI],DL
TEST AX,AX  ;check if ax is 0
JNZ LOOP1

MOV AH,09H
MOV DX,OFFSET RESULT
INT 21H
;-----end the program--------------
MOV AH,4CH
INT 21H
CODE ENDS
END START
于 2013-11-26T10:45:57.907 回答