当我要求用户输入rown
&时,我正在获取符号而不是int。 coln
之后readint
和writestring
。如何让输入的int出现?
.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
答案 0 :(得分:3)
我猜是因为代码的重要部分缺失了
由于readInt
读取并返回一个数字,因此您应该在写入之前将其重新转换为字符串
为了确保这一点,请尝试输入97
(十进制)作为列数和行数。如果我没有弄错,输出消息将是"ENTER AN ARRAY OF axa:"
答案 1 :(得分:0)
Irvine的ReadInt
将输入的数字转换为CPU内部格式" DWORD"。要将其写为ASCII(WriteString
),必须将其转换。由于在发布的程序中每个数字仅保留一个字节并且仅存储AL
,因此我假设只需要转换范围0..9。因此,只需要将一个数字转换为一个ASCII字符。转换表如下所示:
CPU -> ASCII
0 -> 48
1 -> 49
2 -> 50
3 -> 51
4 -> 52
5 -> 53
6 -> 54
7 -> 55
8 -> 56
9 -> 57
Tl;博士:只需将{48}添加到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
一些警告:
1)Irvine的ReadInt
"读取一个32位有符号十进制整数"。因此,EAX
中的数字可以超出范围0..9,而AL
中的数字不是有效数字。要转换EAX
中的整个值,请查看`here。
2)rown
和coln
现在是ASCII字符。在进一步处理之前,它们最终必须转换为整数。
3)DWORD的转换会导致两个或更多的十进制数字稍微复杂一些。必须通过重复除以10来存储剩余的单个数字。