为什么我的code显示垃圾? [英] Why does my code display rubbish?
问题描述
我的code是显示垃圾时,我想打印列表中的每个数字的为好,什么错?输出应该是这样的:
指定数组是:2G; 4 PT 这是为什么垃圾结果
总数为:7
code
承担CS:code,DS:DATA,SS:STK
ORG 0000H数据段
列表DB 2,23,11,4,15,32,$;与去年元素鉴于数组$,表示结束
MESSAGE1 DB给定的数组为:$;消息1
MESSAGE2 DB的总数为:$;消息2
数据终止;堆栈段
STK段STACK
DB 512 DUP(?)
TOS LABEL WORD
STK ENDS; code段
code段
ORG 2000HSTART:
MOV DX,DATA
MOV DS,DX
MOV DX,STK
MOV SS,DX
MOV SP,OFFSET TOS
XOR AX,AX;清除寄存器
XOR BX,BX;初始化索引寄存器LEA DX,MESSAGE1
MOV AH,9H
INT 21HLEA SI,列表MOV CL,0
MOV AL,$再次:
CMP AL,[SI];查找列表的末尾
JE过
MOV DL,LIST [BX];移动数字阵列
ADD DX,30H;数字转换为字符。
MOV AH,2;在屏幕显示该号码
INT 21HINC SI
INC BX
INC CL
JMP AGAIN过度:
LEA DX,MESSAGE2
MOV AH,9H
INT 21HPUSH CX;转移C1至分升INT21 /啊= 2。
POP DX
ADD DX,30H;数字转换为字符。
MOV AH,02H;在打印DL的字符。
INT 21H
MOV AH,4CH;出口。
INT 21Hcode ENDS
年底动工
我想我知道为什么已经不管大于10的数量会显示为字符,但如何让它在显示数字,如13不显示为=?
LIST DB 2,23,11,4,15,32,$
您没有意识到,超过9的值由多个数字的。这就是为什么值2和4出来正确的;您显示第二和4的字符数,但对于23号没有字符需要显示数为2的和的3。
您需要的是一个适当的 int值的字符串函数输出值作为ASCII。
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:7
Code
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
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.
这篇关于为什么我的code显示垃圾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!