Why does my code display rubbish?
My code is display rubbish when I want to print each of the numbers in the list as well, anything wrong? The output should look like this:
THE GIVEN ARRAY IS:2G;4?PT why is this rubbish
THE TOTAL NUMBER IS:7Code
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 开发者_JS百科 ; 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
I think I knew why already whatever the number greater than 10 it will display as character, but how to let it display in number like "13" dont display as "="?
LIST DB 2,23,11,4,15,32,"$"
You are not realizing that the values over 9 consists of more than one numeral. That's why the values 2 and 4 come out correct; you display the "2nd" and "4th" number characters, but there is no character for number 23. You need to display that number as 2 and 3.
What you need is a proper int to string function to output the values as ascii.
精彩评论