0

当我要求用户输入rown&coln和之后,readint我得到的是符号而不是 int。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
4

2 回答 2

2

我只是猜测,因为缺少代码的重要部分。
由于readInt读取并返回一个数字,因此您可能应该在写入之前将其重新转换为字符串。
可以肯定的是,尝试输入97(十进制)作为列数和行数。如果我没记错的话,输出消息将是"ENTER AN ARRAY OF axa:"

于 2011-10-30T08:19:58.620 回答
0

Irvine'sReadInt将输入的数字转换为 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 位有符号十进制整数”。因此,in 的数字EAX可以超出范围 0..9 并且 inAL不是有效数字。要转换整个值,EAX请查看`here

2) atrowncoln现在是 ASCII 字符。在进一步处理之前,它们最终必须转换为整数。

3) 将导致两位或更多十进制数字的 DWORD 转换有点复杂。必须通过反复除以 10 来隔离单个数字并存储余数。

于 2016-01-01T23:38:00.557 回答