2016-04-28 10 views
3

ファイルに書き込み、コードに書き込むためのラベルを作成しましたが、埋めている文字列がファイルに書き込まれていません。DOSBoxで実行中のアセンブリでファイルに書き込む方法

ライト操作:

proc WriteToFile 
    mov ah,40h 
    mov bx,[filehandle] 
    mov cx,255 
    lea dx,[WriteStr] 
    int 21h 
    ret 
endp WriteToFile 

ライティングラベル:

CreatingFile: 
    mov dx,offset c 
    mov ah,9h 
    int 21h 
    mov dx,offset filenameStr 
    mov bx,dx 
    mov [byte ptr bx],13 ;8+1+3+1 
    mov ah,0Ah 
    int 21h 
    mov dx,offset filenameStr + 2 
    mov ah,9h 
    int 21h 
    mov [byte ptr filenameStr+2+8],0 
    call CreateFile 
    ; 

コールWRITETOFILEの-itは、書いた:

WritingToFile: 
    mov dx,offset w 
    mov ah,9h 
    int 21h 
    mov dx,offset filenameStr 
    mov bx,dx 
    mov [byte ptr bx],13 ;8+1+3+1 
    mov ah,0Ah 
    int 21h 
    mov dx,offset filenameStr + 2 
    mov ah,9h 
    int 21h 
    mov [byte ptr filenameStr+2+8],0 
    call OpenFile 
    xor bx,bx 
    call WipeClean 
    mov dx,offset filereaderline 
    mov ah,9h 
    int 21h 
    mov dx,offset WriteStr 
    mov bx,dx 
    mov [byte ptr bx],100 ;8+1+3+1 
    mov ah,0Ah 
    int 21h 
    call WriteToFile 
    call CloseFile 
    call DisplayWriteStr 
    jmp GetCommandLetter 

私は、この手順にことが判明しました事故

call DisplayFileName 
    xor bx,bx 
    call CloseFile 
    jmp GetCommandLetter 

それがファイルでこれを書いた:あるそれは作成されたファイル内

i $$$$$$$$$$$$$ 

HELP LIST: 

----------- 

Commands are: 

/e-Exit 

/h-help 

/1-Says: 'Hello World!' 

$ Error 

$file name consists of 4 letters MUST!! (dont forget to add '.txt' at the end of the name: 'xmpl.txt')$ 

/r/ $ 

/c/ $ 

/w/ $    i $$$$$$$$$$$$$ 

HELP LIST: 

----------- 

Commands are: 

/e-Exit 

/h-help 

/1-Says: 'Hello World!' 

$ Error 

$file name consists of 4 letters MUST!! (dont forget to add '.txt' at the end of the name: 'xmpl.txt')$ 

/r/ $ 

/c/ $ 

/w/ $    " 

、私はファイルを書き込むための私の変数を見たより:

WriteStr db 105,0,13 dup("$") 

それが重複$を説明私はこの変数に問題があると私はほとんど、私はそれをどのように変更することができますどのように動作すると思いますか?

全コード:

あなたのコード内のエラーが見つかり
IDEAL 
MODEL small 
STACK 100h 
DATASEG 

szMsg1 db "Hi! What do you want to do?",10,13,10,13,"/h-help(see all the commands)",10,13,"/e-Exit",10,13,10,13,"$" 
szHelloWorld db 10,13,"Hello World!",10,13,"$" 
ErrorMsg db 10,13,"Illegal Command,Try again!",10,13,"$" 
filenameStr db 13,0,13 dup("$") 
WriteStr db 105,0,13 dup("$") 
help db 10,13,"HELP LIST:",10,13,"-----------",10,13,"Commands are:",10,13," /e-Exit",10,13," /h-help",10,13," /1-Says: 'Hello World!'",10,13,"$" 
filename db ?,0 
filehandle dw 0 
ErrorOpenMsg db 'Error',10,13,'$' 
FileNameLength db "file name consists of 4 letters MUST!! (dont forget to add '.txt' at the end of the name: 'xmpl.txt')","$" 
r db 10,13,"/r/ ","$" 
c db ,10,13,"/c/ ","$" 
w db ,10,13,"/w/ ","$" 
fileString db 255 dup (0) 
space db " ","$" 
CommandMsg db 10,13,"Enter your command:",10,13,"Command: ","$",10,13 
filereaderline db "file's text:","$" 


CODESEG 
proc Exitp 
    mov ax, 4c00h 
    int 21h 
endp Exitp 

proc WipeClean 
    mov [byte ptr fileString + bx], 0 
    inc bx 
    cmp bx, 255 
    jb WipeClean 
    ret 
endp WipeClean 

proc OpenFile 
;Open file 
    mov ah,3Dh 
    xor al,al 
    lea dx,[filenameStr+2] 
    int 21h 
    jc openerror 
    mov [filehandle],ax 
    ret 
openerror: 
    mov dx,offset ErrorOpenMsg 
    mov ah,9h 
    int 21h 
    ret 
endp OpenFile 

proc CreateFile 
    mov ah,3ch 
    mov cx,00000000b 
    lea dx,[filenameStr+2] 
    int 21h 
    jc CreateError 
    mov [filehandle],ax 
    ret 
CreateError: 
    mov dx,offset ErrorOpenMsg 
    mov ah,9h 
    int 21h 
    ret 
endp CreateFile 

proc ReadFile 
    mov ah,3fh 
    mov bx,[filehandle] 
    mov cx,255 
    lea dx,[fileString] 
    int 21h 
    ret 
endp ReadFile 

proc DeleteFile 
    mov ah,41h 
    lea dx,[filenameStr+2] 
    int 21h 
endp DeleteFile 

proc DisplayFileString 
    mov ah,09h 
    lea dx,[fileString] 
    int 21h 
endp DisplayFileString 

proc DisplayWriteStr 
    mov ah,09h 
    lea dx,[WriteStr] 
    int 21h 
endp DisplayWriteStr 

proc DisplayFileName 
    mov ah,09h 
    lea dx,[filenameStr] 
    int 21h 
endp DisplayFileName 

proc KeyStroke 
    xor ax,ax 
    int 16h 
endp KeyStroke 

proc WriteToFile 
    mov ah,40h 
    mov bx,[filehandle] 
    mov cx,255 
    lea dx,[WriteStr] 
    int 21h 
    ret 
endp WriteToFile 

proc CloseFile 
    mov ah,3Eh 
    mov bx,[filehandle] 
    int 21h 
    ret 
endp CloseFile 

start: 
    mov ax, @data 
    mov ds, ax 

    mov ah,0 
    mov al,2 
    int 10h 

    mov dx,offset szMsg1 
    mov ah,9h 
    int 21h 
    jmp GetCommandLetter 

PrintLine: 
    mov dx, offset szHelloWorld 
    mov ah, 9h 
    int 21h 
    jmp GetCommandLetter 

_Error: 

    mov dx,offset ErrorMsg 
    mov ah,9h 
    int 21h 

GetCommandLetter: 
    mov dx,offset CommandMsg 
    mov ah,9h 
    int 21h 

    mov ah, 1h 
    int 21h 
    mov bl,al 

    mov ah, 1h 
    int 21h 
    mov bh,al 
compare:  

    cmp bl,'/' 
    jne _Error 

    cmp bh,'h' 
    je _help 

    cmp bh,'H' 
    je _help 

    cmp bh,'1' 
    je PrintLine 

    cmp bh,'e' 
    je _Exitp 

    cmp bh,'E' 
    je _Exitp 

    mov dx,offset space 
    mov ah,9h 
    int 21h 
    mov dx,offset FileNameLength 
    mov ah,9h 
    int 21h 


    cmp bh,'c' 
    je CreatingFile 

    cmp bh,'C' 
    je CreatingFile 

    cmp bh,'r' 
    je GetFileName 

    cmp bh,'R' 
    je GetFileName 

    cmp bh,'w' 
    je WritingToFile 

    cmp bh,'W' 
    je WritingToFile 

    jmp _Error 

_Exitp: 
call Exitp 

_help: 
    mov dx,offset help 
    mov ah,9h 
    int 21h 
    jmp GetCommandLetter 

GetFileName: 
    mov dx,offset r 
    mov ah,9h 
    int 21h 
    mov dx,offset filenameStr 
    mov bx,dx 
    mov [byte ptr bx],13 ;8+1+3+1 
    mov ah,0Ah 
    int 21h 
    mov dx,offset filenameStr + 2 
    mov ah,9h 
    int 21h 
    mov [byte ptr filenameStr+2+8],0 
    call OpenFile 
    xor bx,bx 
    call WipeClean 
    call ReadFile 
    mov dx,offset filereaderline 
    mov ah,9h 
    int 21h 
    call DisplayFileString 
    call CloseFile 
    jmp GetCommandLetter 

CreatingFile: 
    mov dx,offset c 
    mov ah,9h 
    int 21h 
    mov dx,offset filenameStr 
    mov bx,dx 
    mov [byte ptr bx],13 ;8+1+3+1 
    mov ah,0Ah 
    int 21h 
    mov dx,offset filenameStr + 2 
    mov ah,9h 
    int 21h 
    mov [byte ptr filenameStr+2+8],0 
    call CreateFile 
    call WriteToFile 
    call DisplayFileName 
    xor bx,bx 
    call CloseFile 
    jmp GetCommandLetter 

WritingToFile: 
    mov dx,offset w 
    mov ah,9h 
    int 21h 
    mov dx,offset filenameStr 
    mov bx,dx 
    mov [byte ptr bx],13 ;8+1+3+1 
    mov ah,0Ah 
    int 21h 
    mov dx,offset filenameStr + 2 
    mov ah,9h 
    int 21h 
    mov [byte ptr filenameStr+2+8],0 
    call OpenFile 
    xor bx,bx 
    call WipeClean 
    mov dx,offset filereaderline 
    mov ah,9h 
    int 21h 
    mov dx,offset WriteStr 
    mov bx,dx 
    mov [byte ptr bx],100 ;8+1+3+1 
    mov ah,0Ah 
    int 21h 
    call WriteToFile 
    call CloseFile 
    call DisplayWriteStr 
    jmp GetCommandLetter  




exit: 
    mov ax, 4c00h 
    int 21h 
END start 
+0

のmov dxは、WriteStrオフセット mov bx、dx mov [byte ptr bx]、100; 8 + 1 + 3 + 1 mov ah、0Ah int 21hこれは文字列のユーザー入力を要求するコードです – Warrior0201

+0

質問を更新しました。何かを見つけた – Warrior0201

+0

私はaddeした私のプログラムでは、それらのdは私が行った編集を見て、retはここに表示されていませんが、私のコンピュータ上で私はそれを変更しました – Warrior0201

答えて

3

:あなたはそれを書くことができないので、ファイルは、READ ONLYモードで開かれている:

proc OpenFile 
;Open file 
    mov ah,3Dh 
    mov al,2 ;<================== 0:READ ONLY, 1:WRITE ONLY, 2:READ/WRITE. 
    lea dx,[filenameStr+2] 
    int 21h 
    jc openerror 
    mov [filehandle],ax 
    ret 
openerror: 
    mov dx,offset ErrorOpenMsg 
    mov ah,9h 
    int 21h 
    ret 
endp OpenFile 
+0

ありがとう男!それが問題になるとは決して考えなかった:P – Warrior0201