這裏的問題是我必須在MASM中查找斐波那契數列達到給定的限制。我必須從文件讀取該限制。例如,存儲在名爲「 Test.txt的」。無法從MASM文件中讀取一個數字
這裏是我的代碼
.model small
.stack
.data
msg0 db 'enter the filename $'
msg1 db 'file found $'
msg2 db 'file not found $'
msg3 db 'file read successfull $'
msg4 db 'file read not successfull $'
newline db 10,13,'$'
limit dw ?
filename db 50 dup(?)
filedata db 50 dup(?)
pointerpos db 100 dup(?)
.code
print macro msg
push ax
push dx
mov ah,09h
mov dx,offset msg
int 21h
pop dx
pop ax
endm
.startup
print msg0
mov si,offset filename
call readstring
mov dx,offset filename
mov al,00h
mov ah,3dh
int 21h
jc failed
print msg1
mov bx,ax
mov al,00h
mov dx,offset pointerpos
mov ah,42h
int 21h
jc failed3
mov dx,offset filedata
mov cx,1
mov ah,3fh
int 21h
jc failed1
print newline
print msg3
mov si,offset filedata
call readlimit
mov ax,limit
call display
.exit
failed: print newline
print msg2
.exit
failed1: print newline
print msg4
.exit
failed3: print newline
.exit
readstring proc near
push ax
push si
l1: mov ah,01h
int 21h
cmp al,0dh
je skip
mov [si],al
inc si
jmp l1
skip: mov al,0h
mov [si],al
pop si
pop ax
ret
readstring endp
readlimit proc near
push ax
push bx
push cx
push dx
mov bx,0
mov cx,10
l2: mov al,[si]
cmp al,'0'
jb last
cmp al,'9'
ja last
sub al,30h
mov ah,0
push ax
mov ax,bx
mul cx
mov bx,ax
pop ax
add bx,ax
last: mov limit,bx
pop dx
pop cx
pop bx
pop ax
ret
readlimit endp
display proc near
push ax
push bx
push cx
push dx
mov bx,10
mov cx,0
l5: mov dx,0
div bx
cmp ax,0
je l4
inc cx
push dx
jmp l5
l4: pop dx
add dl,30h
mov ah,02h
int 21h
loop l4 ;decrement cl by 1 and check if cl==0
pop dx
pop cx
pop bx
pop ax
ret
display endp
end
在這裏的錯誤我m到處是一些垃圾值顯示出來,當我打印,我從文件中讀取的值。
注意:我還沒有嘗試打印斐波那契數列,因爲我無法從文件中讀取數字。
爲什麼這個問題擱置,而它已經有了答案? – Midhun0407