|  | 
 
 发表于 2019-4-15 23:41:27
|
显示全部楼层 
| 先试试这个 
 
 复制代码assume cs:code, ds:data
data segment
        fd dw 0
        filename db 'main.asm', 0
        buffer db 1024 dup(0)
        err_msg db 'error!', 0
data ends
code segment
start:
        ; 打开文件
        mov        ax, data
        mov        ds, ax
        
        mov        dx, offset filename
        mov        ax, 3d00h
        int        21h
        jc        print_error_message
        mov        fd, ax
        
        ; 读文件
        mov        bx, fd
        mov        dx, offset buffer
        mov        cx, 0ffffh
        mov        ah, 3fh
        int        21h
        jc        print_error_message
        mov        bx, ax
        mov        buffer[bx], 0
        
        ; 输出文件内容
        mov        bx, offset buffer
        call        print_string
        
        ; 关闭文件
        mov        bx, fd
        mov        ah, 3eh
        int        21h
        jmp        done
        
print_error_message:
        mov        bx, offset err_msg
        call        print_string
        
done:
        mov        ax, 4c00h
        int        21h
        
; 输出以0结尾的字符串
; 输入:BX -> 字符串
print_string:
        push        bx
@@:
        mov        al, byte ptr [bx]
        cmp        al, 0
        je        @f
        
        push        bx
        mov        bl, 07h
        mov        ah, 0eh
        int        10h
        pop        bx
        
        inc        bx
        jmp        @b
@@:
        pop        bx
        ret
        
code ends
end start
 | 
 |