Why is my code showing garbage?

My code displays garbage, when I want to print each of the numbers in the list, is something wrong? The result should look like this:

THIS MASS: 2G; 4? PT why is this trash
GENERAL NUMBER: 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 any number greater than 10 would already be displayed as a character, but how to let it display a number like "13" does not appear as "="?

+4
source share
1 answer
 LIST DB 2,23,11,4,15,32,"$" 

You do not understand that values ​​over 9 consist of more than one number. This is why values ​​2 and 4 come out correctly; you show the characters “2nd” and “4th”, but there is no character for number 23. You need to display this number as 2 and 3.

You need the correct int function for the string to output values ​​as ascii.

+6
source

Source: https://habr.com/ru/post/1339129/


All Articles