-1

こんにちは、アセンブリの初心者です。ファイルを開いて値「整数」を読み取り、整数をバッファに保存して画面に出力することはありません。これは私のコードです。動作しません

include inout.asm
.model small,c
.486
.stack
.data
org 100h ; .com memory layout 
buf db ?
file db "c:\rtasm\bin\file.txt";the file name in bin
.code

mov dx, offset file ; address of file to dx 
mov al,0 ; open file (read-only) 
mov ah,3dh 
int 21h ; call the interupt 
mov bx,ax ; put handler to file in bx 


mov ah,40h
mov bx,ax
mov cx,2h                 ;; how many bytes you want to read
mov dx,offset buf  ;; where you want to store that data (see note on Offset above)
int 21h

call putchar,offset buf; print char on the screen


mov ah,3eh
mov bx,ax
int 21h 
.exit
END 
4

1 に答える 1

2

Int 21h function 3Dh ("OPEN EXISTING FILE")ds:dx. 提供している文字列にはゼロ ターミネータがありません。ファイル名は として宣言する必要がありますfile db "c:\rtasm\bin\file.txt",0

関数 3Dh と 40h はどちらも、失敗するとエラー コードを返します。これらを確認し、エラーが発生した場合は、操作が常に成功すると想定するのではなく、ユーザー (この場合は自分自身) に通知する必要があります。

別の問題は、次のコードです。

mov bx,ax ; put handler to file in bx 

mov ah,40h      
mov bx,ax    <-- gives you a nonsense file handle since ah now is 40h
mov cx,2h          ;; how many bytes you want to read
mov dx,offset buf  ;; where you want to store that data (see note on Offset above)
int 21h

2 番目は、ファイル ハンドルが既に含まれているmov bx,axため不要です。実際、 ( ) の上位部分を値 40hbxで上書きしたため、不要であるだけでなく、正しくもありません。また、1 バイト分のスペースしかないバッファーに 2 バイトを読み込んでいるという事実もあります。axah

于 2013-05-01T17:55:04.147 に答える