Reputation: 33
I've written this code and for some reason it only prints part of the sentence and it also doesn't assign the number from DL
to the string and prints a 'heart' instead.
I checked in TurboDebugger and everything, beside that part, went perfectly.
I add the relevant parts:
.MODEL SMALL
.STACK 100h
.DATA
ARR1 DW 333,20989,3456,2082
ARR2 DW 333,15,5436,2082
ARR3 DW ?
ANSWER DB 'The last digit is: X',13,10,'$'
TEN DW 10
.CODE
MOV AX,@DATA ; DS can be written to only through a register
MOV DS,AX ; Set DS to point to data segment
MAX:
CMP AX,10
;MAX<10
JL LESSTHAN10
;MAX>10
MOV DX,0
DIV TEN
MOV ANSWER[19],DL
JMP PRINTANSWER
PRINTANSWER:
MOV AH,9 ; Set print option for int 21h
MOV DX,OFFSET ANSWER ; Set DS:DX to point to answerString
INT 21h ; Print DisplayString
Here is a screenshot of my attempt of assembling this:
Upvotes: 1
Views: 514
Reputation: 9899
for some reason it only prints part of the sentence
This happens because you are overwriting the first 6 characters from your message ANSWER when you write something in the array ARR3.
Make sure to provide enough space for this 3rd array by writing:
ARR3 DW 4 dup (?)
ANSWER DB 'The last digit is: X',13,10,'$'
it also doesn't assign the number from DL to the string and prints a 'heart' instead.
The remainder from the division by 10 gave a number from 0 to 9 that you want to print as a character. You need to actually turn it into a character first. This is done by adding 48 to it. An elegant way of doing this is by writing add dl, "0"
.
DIV TEN
add dl, "0"
MOV ANSWER[19],DL
Upvotes: 2