Reputation: 13
I'm getting symbols instead of int when I ask the user to enter the rown
& coln
with the readint
and writestring
afterward. How can I get the int entered to show up?
.686
.MODEL FLAT, STDCALL
.STACK
INCLUDE Irvine32.inc
.Data
txt1 byte "ENTER NUM OF ROWS:",0dh,0ah,0
txt2 byte "ENTER NUM OF COLUMNS:",0dh,0ah,0
txt3 byte "ENTER AN ARRAY OF"
rown byte 0,"x" ;rows number
coln byte 0,":",0dh,0ah,0 ;columns number
.CODE
main PROC
mov edx,offset txt1
call writestring ;asks the user to enter the rows number
call readint
mov rown,al
mov edx,offset txt2
call writestring
call readint ;asks the user to enter the columns number
mov coln,al
mov edx, offset txt3
call writestring ;;;;; here is the problem !!!!!
call waitmsg
exit
main ENDP
END main
Upvotes: 0
Views: 806
Reputation: 14409
Irvine's ReadInt
converts the inputted number into the CPU internal format "DWORD". To write it as ASCII (WriteString
) it must be converted. Since in the posted program is reserved only one byte for each number and only stored AL
, I assume that only the range 0..9 has to be converted. Hence, just one number has to be converted to one ASCII character. A conversion table looks like this:
CPU -> ASCII
0 -> 48
1 -> 49
2 -> 50
3 -> 51
4 -> 52
5 -> 53
6 -> 54
7 -> 55
8 -> 56
9 -> 57
Tl;dr: Just add 48 to AL
:
;.686 ; Included in Irvine32.inc
;.MODEL FLAT, STDCALL ; Included in Irvine32.inc
;.STACK ; Not needed for .MODEL FLAT
INCLUDE Irvine32.inc
.DATA
txt1 byte "ENTER NUM OF ROWS:",0dh,0ah,0
txt2 byte "ENTER NUM OF COLUMNS:",0dh,0ah,0
txt3 byte "ENTER AN ARRAY OF "
rown byte 0,"x" ;rows number
coln byte 0,":",0dh,0ah,0 ;columns number
.CODE
main PROC
mov edx,offset txt1
call WriteString ;asks the user to enter the rows number
call ReadInt
add al, 48
mov rown, al
mov edx, offset txt2
call WriteString
call ReadInt ;asks the user to enter the columns number
add al, 48
mov coln, al
mov edx, offset txt3
call WriteString
call WaitMsg
exit
main ENDP
END main
Some caveats:
1) Irvine's ReadInt
"reads a 32-bit signed decimal integer". Thus, the number in EAX
can be out of the range 0..9 and in AL
is anything else than a valid number. To convert the whole value in EAX
take a look `here.
2) At rown
and coln
are now ASCII characters. They eventually have to be converted to integer before further processing.
3) A conversion of a DWORD that would lead to two decimal digits or more is a little bit more complicated.The single digits must be isolated by repeatedly divide by 10 and store the remainder.
Upvotes: 0
Reputation: 22979
I'm juts guessing since the important part of the code is missing.
Since readInt
read and returns a number, you should probably re-convert it to a string before writing.
Just to be sure, try to enter 97
(decimal) as the number of columns and rows. If I am not mistaken, the output message will be "ENTER AN ARRAY OF axa:"
Upvotes: 2