居民功能没有正确执行

时间:2014-06-15 12:25:27

标签: assembly dos x86-16 tasm

我再次面对面显示文件名称的问题。为什么又一次?

驻留功能会更改目录并显示行,但不显示文件名。我从其他程序引起功能。

.model  tiny
.code
.186
org 100h
main:  mov  ah, 33h
       int  60h
       ret
       end  main

如果功能数量不正确,将显示错误: “功能%somefunction%未实现”。

我的功能数量33h,我必须收到消息“具有最早创建日期的文件:%myoldfile%”,但是 我只收到没有文件名的行。

.MODEL tiny
.code
.386

org     100h

main:


jmp init

Int_60h:
xor     cx, cx
mov     cl, ah
push    ds
pusha
mov     bl, ah
sal     bx, 1
mov     ax, cs
mov     ds, ax
call    TAB[bx]
popa
mov     bl, count
pop     ds
iret






OldFile PROC 

mov ah,3bh
mov dx,offset root ; Change directory to the root
int 21h

lea dx, dta ; dta: disk transfer area
mov ah, 1AH ; SET DISK TRANSFER AREA ADDRESS
int 21h ; DOS INTERRUPT

mov ah, 4EH ; FIND FIRST MATCHING FILE
lea dx, path ; DS:DX -> ASCIZ file specification (may include path and wildcards)
mov cx, 0 ; file attribute mask
int 21h ; DOS INTERRUPT

call store_dta


FindNext:

mov ah, 4FH ; FIND NEXT MATCHING FILE
int 21h ; DOS INTERRUPT
jc Finish

; compare filedates & filetimes
lea si, dta_hold ; DTA of the oldest file
lea di, dta ; DTA of the just found file
mov ax, [si+18h] ; filedate
mov bx, [di+18h] ; filedate
cmp ax, bx
jc FindNext ; just found file is newer
jne Older
; filedates are identical
mov ax, [si+16h] ; filetime
mov bx, [di+16h] ; filetime
cmp ax, bx
jc FindNext

Older: ; just found file is older
call store_dta ; copy dta to dta_hold
jmp FindNext

Finish:
call print_filename ; print the last filename




store_dta PROC
mov cx, (128/2) ; size of DTA in WORDs (half of BYTEs)
lea si, dta
lea di, dta_hold
rep movsw ; copy CX times DS:SI => ES:DI
ret
store_dta ENDP

print_filename PROC

lea dx, line ; new line
mov ah, 09h ; WRITE STRING TO STANDARD OUTPUT
int 21h ; DOS INTERRUPT

lea di, dta_hold + 1Eh
mov dx, di ; start of filename
_B: ; look for NULL (ASCIZ-termination)
cmp BYTE PTR [di], 0
je _F
inc di
jmp _B
_F: ; replace NULL by '$'
mov [di], BYTE PTR '$' ; end-of-string delimiter for INT 21h/09h
mov ah, 09h ; WRITE STRING TO STANDARD OUTPUT
int 21h ; DOS INTERRUPT

lea dx, LF ; new line
mov ah, 09h ; WRITE STRING TO STANDARD OUTPUT
int 21h ; DOS INTERRUPT
ret

dta db 128 DUP(?)
dta_hold db 128 DUP(?)
path db "*.*",0
LF db 13,10,'$'
root db "/",0
line db "The file with the oldest date of creation: ",'$'

print_filename ENDP

    OldFile ENDP

    Zproc   proc    near 
xor     ax, ax
mov al, cl
mov cx, 5           
    L1:                 
xor dx, dx          
mov di, cx          
div hexdel
mov bx, dx          
mov dl, chararray[bx]   
mov Znum[di-1], dl  
dec cx
cmp ax, 0   
jne L1          
mov si, offset Zmessage1
 l4:    mov al, [si]
mov ah, 0Eh
inc si
int 10h
cmp byte ptr [si], '$'
jne l4
    ret
Zproc   endp




TAB dw  51 DUP (Zproc), (OldFile), 204 DUP (Zproc)
hexdel          dw  16
Zmessage1 db "Function "
Znum    db  3 dup (?)
Zmessage2 db "h is not realized.", 0Dh, 0Ah, '$'
count   db      (?)
chararray   db '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',      'D', 'E', 'F' 

init:
mov ax,2560h
mov dx,offset Int_60h
int 21h
mov dx, (init-main+10Fh)/16
mov ah, 31h
int 21h
end main

1 个答案:

答案 0 :(得分:0)

主要问题是您使用call TAB[bx]调用了您的函数,但未正确填充BXmov bl, ah是不够的,因为BH的值对BX也有影响。在填写XOR BX, BX之前写下BL

xor     bx,bx
mov     bl, ah

第二个是程序OldFile无法正确返回。在正确的位置插入ret

Finish:
call print_filename ; print the last filename
ret

第三:程序store_dta需要初始化ES

mov     ds, ax
mov     es, ax
call    TAB[bx]