A2118: 无法在TINY模型中使用段地址引用。

huangapple go评论58阅读模式
英文:

A2118: cannot have segment address references with TINY model

问题

The error message you're encountering, "A2118: cannot have segment address references with TINY model," suggests that there's an issue with segment address references in your assembly code when using the TINY memory model.

In TINY memory model, you should not be using segment address references because TINY model assumes that the code, data, and stack segments are all in one segment. However, in your code, you have used the @data segment to load DS, which is not compatible with the TINY model.

To resolve this error, you should remove the following lines from your code:

mov ax, @data
mov ds, ax

These lines are not needed in the TINY model because it uses a single segment for everything.

After making this change, you can try compiling your code again with the "ml.exe /AT filename.asm" command, and it should work without the A2118 error.

英文:

The task is to write an assembly language program that finds the first file in the directory and shows the time of its creation. When you launch the program, nothing happens. Where can the error be? Compilation is performed using MASM611 on DOSBox, using the command "ml.exe filename.asm".

.model tiny
.stack 100h

.data
    DTA db 128 dup(0)
    path db "C:\*.*", 0
    filename db 13 dup(0)
    creation_time db "File created on: ", 0

.code
main proc
    mov ax, @data
    mov ds, ax

    mov ah, 1Ah ; Set Disk Transfer Area (DTA)
    mov dx, offset DTA
    int 21h

    ; Set the path to the catalog
    mov dx, offset path
    mov ah, 4Eh ; Find First File
    int 21h

    ; Start the file search cycle
search_loop:
    ; Check if the file is found
    cmp al, 0 ; AL = 0, if the file is not found or everything has already been checked
    je exit_search

    ; Print the time of file creation
    mov dx, offset creation_time
    mov ah, 09h ; String output
    int 21h

    ; Upload the year and month of creation
    mov cx, word ptr [DTA+20h] ; Year
    mov bx, word ptr [DTA+22h] ; Month

    ; Print year
    mov ah, 02h ; Character output
    mov dl, ch ; Outputting the most significant byte (tens)
    add dl, 30h ; Convert a number to a character
    int 21h

    mov dl, cl ; Output of the low byte (one)
    add dl, 30h ; Convert a number to a character
    int 21h

    ; Print the month
    mov ah, 02h ; Character output
    mov dl, bh ; Outputting the most significant byte (tens)
    add dl, 30h ; Convert a number to a character
    int 21h

    mov dl, bl ; Output of the low byte (one) 
    add dl, 30h ; Convert a number to a character
    int 21h

    ; Print a new line
    mov dl, 0Dh ; CR
    int 21h
    mov dl, 0Ah ; LF
    int 21h

    ; Find the following file
    mov ah, 4Fh ; Find Next File
    int 21h

    jmp search_loop ; Repeat the file search cycle

exit_search:
    mov ah, 4Ch ; End the program
    int 21h

main endp
end main

If you compile using the command "ml.exe /AT filename.asm", next error occurs:
> A2118: cannot have segment address references with TINY model

Maybe someone knows what the reason is?

答案1

得分: 4

它在抱怨mov ax, @data。在.com可执行文件中不要这样做(或者mov ds, ax),因为没有DOS可以填充段值的元数据。

当一个.com可执行文件启动时,DS已经被正确设置(与其他段相同的值,这就是tiny内存模型的作用)。使用org 100h告诉汇编器相对于这些段基址你的程序顶部的偏移,这样偏移量才能正确地工作作为绝对地址。

一个.com可执行文件只是一个平面二进制文件,执行从顶部开始(文件的第一个字节)。在输出文件中看不到节,但是汇编器会在源顺序之前将.code放在.data之前,所以执行将从你的.code顶部开始。所以实际上这并不是一个问题,感谢@Michael Petch指出这一点。

英文:

It's complaining about mov ax, @data. Don't do that (or the mov ds, ax) in a .com executable, because there's no metadata for DOS to fill in the segment value.

DS is already set correctly (to the same value as the other segments, that's what the tiny memory model is) when a .com executable starts. Use org 100h to tell the assembler what offset the top of your program will have relative to those segment bases, so offsets work correctly as absolute addresses.


A .com executable is just a flat binary and execution begins at the top (first byte of the file). Sections aren't visible in the output file, but assemblers will put .code first, before .data, regardless of source order, so execution will begin at the top of your .code. So that's actually not a problem, thanks @Michael Petch for pointing that out.

huangapple
  • 本文由 发表于 2023年5月20日 20:51:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76295318.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定