-2

It was required to change the program from ".exe" in".com".

  • I removed the stack and data segments because i received errors about their existence.
  • I renamed the file in ".com".

But the program doesn't work now (it is displaying nothing). I think it may be due to movsw, but I do not understand how it works.

.MODEL small
.code
.386

org 100h

Start:

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: ",'$'

mov es, ax                  ; for movsw
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
mov ax,4c00h
int 21h

main ENDP

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
print_filename ENDP

END Start
Seki
  • 11,135
  • 7
  • 46
  • 70
lifetowin
  • 107
  • 2
  • 11

1 Answers1

2

A .COM-program starts at the beginning of the file, there is no specific entry point. So the first instruction is dta db 128 DUP(?) which is no instruction. Move the whole data-block to the end of the program (before the END Start directive.

You don't need to initialize ES or DS, since they are initialized by default to CS.But you deleted by accident the main PROC line. So replace mov es, ax ; for movsw by main PROC.

The correct .MODEL is 'tiny', not 'small'. Correct the line accordingly.

Add the "tiny"-switch (/t) to your TLINK call.

rkhb
  • 14,159
  • 7
  • 32
  • 60