@earthen94

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

MS-DOSでファイル読み込みに失敗

解決したいこと

MS-DOS実機上でファイル読み込みを実装したいのですが、画像の通り失敗してしまいます。
詳しい方がおられましたらご教示頂けますと幸いです。

20260921224008_bb99e4a9e4daeb183b19b9f1b434bbae.jpeg

該当するソースコード

MASMは難しいのでNASMでアセンブルしています。

nasm -f bin mscom.asm -o MSCOM.COM
nasm -f bin mscom.asm -o MSCOM.COM -l mscom.lst
mscom.asm
[org 0x100]

    push cs
    pop ds

    mov ax, 0900h
    mov dx, msg_test
    int 21h

    ; DS退避
    mov ax, ds
    mov [pspseg],ax
    
    ; ファイルを開く
    mov ah, 3dh
    mov al, 0   ; 読み込み専用
    mov dx, filename
    int 21h
    jc error
    mov [filehandle], ax
    
    ; 本来はここでファイルの大きさを調べた上で必要な分のメモリを確保したい
    ; 後日実装する

    ; メモリ確保申請 AX:0〜
    mov ax, 4800h
    mov bx ,4    ; 16*4=64バイト (16バイト毎) 64にしたら失敗した。
    int 21h
    jc error
    mov [memseg], ax
    
    ; DS:DXに読み込む
    mov bx, filehandle
    mov cx, 32 ; 読み込むバイト数
    mov ax, memseg ; ファイルの展開先DS:DXを設定
    mov ds, ax
    mov dx, 0
    mov ax, 3f00h
    int 21h
    jc error

    ; ここで何かする

    ; 閉じる
    
    mov bx, filehandle
    int 21h
    jc error
    
    ; DOSへ戻る
    mov ax, [pspseg]
    mov ds, ax
    
    mov ax, 0900h
    mov dx, msg_ok
    int 21h

    mov ax, 4c00h
    int 21h
    
error:
    mov ax, [pspseg]
    mov ds, ax
    
    mov ax, 0900h
    mov dx, msg_err
    int 21h

    mov ax, 0x4c01
    int 21h 
 :
msg_test: db 'test', 13, 10, '$'
msg_ok:  db 'seikou', 13, 10, '$'
msg_err: db 'err', 13, 10, '$'

pspseg: dw 0     ; DOSに読み込まれた時のDS保存
memseg: dw 0     ; 確保したメモリのセグメント
filehandle: dw 0 ; 開いたファイルの識別子
filename: db 'TEST.TXT', 0

環境

開発

CPU : Intel® Core™ i5-7200U CPU @ 2.50GHz × 4
OS : Ubuntu 22.04.5 LTS

実行

CPU : NEC V30
OS : MS-DOS 6.22

0 likes

1Answer

環境ないので実行してませんが、入力のahにファンクションコードがないのでは?

    ; 閉じる

+  mov ax, 3e00h
    mov bx, filehandle
    int 21h
    jc error
0Like

Your answer might help someone💌