need some help with my code in Assembly. For my class I had to write some code a
ID: 3603897 • Letter: N
Question
need some help with my code in Assembly. For my class I had to write some code and start building off it which is all done in MASM. I was able to do most of the assignment but now I am stuck! Currently, the code asks the user for a value between 0 and 99. It then takes this number input and loops for that amount of times. The loop prints out text and then a count for how many times the progam has looped for. The program works for the most part. If I enter in 11 then it loops 11 times. However, the counter, when it prints takes the ASCII code and ends up printing symbols when it is past a count of 9. I tried slightly modifying it to accept two inputs of a single digit and combine them, but then I got lost trying to incement the count.
Long story short, how do I modify my code to not print in ASCII but rather print the numbers from 0 - 99. Like I said, the code works and loops correctly, I just can't get it to print correctly. My current code is below:
---------------------------------------------------------------------------------------------------
cseg segment 'code'
assume cs:cseg, ds:cseg, ss:cseg, es:cseg
org 100h
start: mov dx, offset Intro
mov ah, 09
. int 21h
mov dx, offset Prompt
int 21h
read: mov ah, 1
int 21h
mov cl, 0ah
sub al, 30h
mul cl
mov bl, al
mov ah, 1
int 21h
sub al, 30h
add bl, al
mov ch, 0
again: mov dx, offset Hello
mov ah, 09
int 21h
mov dx, offset Num_msg
int 21h
inc byte ptr Num_msg
inc ch
cmp ch, bl
jl again
done: mov Num_msg, 30h
mov ah, 4ch
int 20h
org 200h
Intro db "Insert name here", 0ah, 0ah, 0dh, "$"
Hello db "Hello World", 20h, 20h, "$"
Prompt db "Enter a number between 1 and 99:", 20h, 20h, 0ah, 0dh, "$"
Num_msg db 30h, 13, 10, "$"
cseg ends
end start
---------------------------------------------------------------------------------------------------
Currently this is what it outputs to the screen:
Insert name here
Enter a number between 1 and 99:
15Hello World 0
Hello World 1
Hello World 2
Hello World 3
Hello World 4
Hello World 5
Hello World 6
Hello World 7
Hello World 8
Hello World 9
Hello World :
Hello World ;
Hello World <
Hello World =
Hello World >
Explanation / Answer
cseg segment 'code'
assume cs:cseg, ds:cseg, ss:cseg, es:cseg
org 100h
start: mov dx, offset Intro
mov ah, 09
. int 21h
mov dx, offset Prompt
int 21h
read: mov ah, 1
int 21h
mov cl, 0ah
sub al, 30h
mul cl
mov bl, al
mov ah, 1
int 21h
sub al, 30h
add bl, al
mov ch, 0
again: mov dx, offset Hello
mov ah, 09
int 21h
mov dx, offset Num_msg
int 21h
inc byte ptr Num_msg
inc ch
cmp ch, bl
jl again
done: mov Num_msg, 30h
mov ah, 4ch
int 20h
org 200h
Intro db "Insert name here", 0ah, 0ah, 0dh, "$"
Hello db "Hello World", 20h, 20h, "$"
Prompt db "Enter a number between 1 and 99:", 20h, 20h, 0ah, 0dh, "$"
Num_msg db 30h, 13, 10, "$"
cseg ends
end start
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.