获取符号而不是 int

发布于 2024-12-12 20:09:20 字数 863 浏览 0 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弃爱 2024-12-19 20:09:20

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

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:"

冷弦 2024-12-19 20:09:20

欧文的 ReadInt< /a> 将输入的数字转换为 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;dr:只需将 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 中的整个值,请查看 `在这里

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文