4
我想要打印列表中的每個數字時,我的代碼顯示垃圾,有什麼不對嗎?輸出應該是這樣的:爲什麼我的代碼顯示垃圾?
給定的數組爲:2G; 4 PT 這是爲什麼垃圾
總數爲:7
代碼
ASSUME CS:CODE , DS : DATA, SS: STK
ORG 0000H
DATA SEGMENT
LIST DB 2,23,11,4,15,32,"$" ; Given Array with last element $ to indicate end
MESSAGE1 db "THE GIVEN ARRAY IS:$" ;message 1
MESSAGE2 db "THE TOTAL NUMBER IS:$" ;message 2
DATA ENDS
;stack segment
STK SEGMENT STACK
DB 512 DUP (?)
TOS LABEL WORD
STK ENDS
; code segment
CODE SEGMENT
ORG 2000H
START :
MOV DX, DATA
MOV DS, DX
MOV DX, STK
MOV SS, DX
MOV SP, OFFSET TOS
XOR AX, AX ; Clear register
XOR BX, BX ; Initialise index register
LEA DX, MESSAGE1
MOV AH, 9h
INT 21H
LEA SI , list
MOV CL,0
MOV AL,"$"
AGAIN:
CMP AL,[SI] ; look for end of list
JE over
MOV DL, LIST[BX] ; Move array numbers
ADD DX, 30H ; convert number to character.
MOV AH, 2 ;display the number at the screen
INT 21H
INC SI
INC BX
INC CL
Jmp AGAIN
over:
LEA DX, MESSAGE2
MOV AH, 9h
INT 21H
PUSH CX ; transfer cl to dl for int21/ah=2.
POP DX
ADD DX, 30H ; convert number to character.
MOV AH, 02H ; prints the character in dl.
INT 21H
MOV AH, 4CH ; exit.
INT 21H
CODE ENDS
END START
我我想知道爲什麼已經有數字大於10的數字會顯示爲字符,但是如何讓它像「13」一樣顯示數字,不顯示爲「=」?
此代碼需要重新格式化!這是作業嗎?順便不要使用標籤。 – 2011-02-10 04:56:59