2011-10-30 35 views
0

我越來越符號代替INT當我問用戶與readintwritestring之後進入rown & coln。我怎樣才能讓輸入的int顯示出來?獲取符號而不是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

這是什麼處理器/指令集? –

+0

您應該確定平臺和o/s。任何人能夠回答這個問題的機會都很渺茫。我們沒有'readint'等代碼。 –

+1

您可能需要先將數字轉換爲文本,或者如果每個數字都存在這樣的函數,則可以使用'writeint'函數。 – user786653

回答

3

我只是猜測,因爲代碼的重要部分缺失。
由於readInt讀取並返回一個數字,您應該在寫入之前將其重新轉換爲字符串。
可以肯定的是,請嘗試輸入97(十進制)作爲列和行的數量。如果我沒有弄錯,輸出信息將會是"ENTER AN ARRAY OF axa:"

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 

鉈;博士:只需添加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)歐文的ReadInt「讀取32位帶符號的十進制整數」。因此,EAX中的數字可能超出範圍0..9,並且AL不是有效數字。要轉換EAX的整個值,請看看`here

2)在rowncoln現在是ASCII字符。在進一步處理之前,它們最終必須轉換爲整數。

3)將會導致兩位十進制數字或更多的DWORD轉換稍微複雜一點。必須通過重複除以10並存儲餘數來隔離單個數字。