生成.com而不是.exe

时间:2014-06-15 08:34:34

标签: assembly dos x86-16 tasm

需要从“.com”中的“.exe”更改程序。

  • 我删除了堆栈和数据段,因为我收到了有关它们存在的错误。
  • 我在“.com”中重命名了该文件。

但是程序现在不起作用(它什么也没显示)。我想这可能是由于movsw,但我不明白它是如何运作的。

.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

1 个答案:

答案 0 :(得分:2)

.COM程序从文件的开头开始,没有特定的入口点。所以第一条指令是dta db 128 DUP(?),这不是指令。将整个数据块移动到程序的末尾(在END Start指令之前。

您无需初始化ESDS,因为它们默认初始化为CS。但您偶然删除了main PROC行。因此,请mov es, ax ; for movsw替换main PROC

正确的.MODEL是'微小的',而不是'小'。相应地纠正这条线。

将“tiny”-switch(/ t)添加到您的TLINK调用中。