Cannot access label through segment registers, error in assembly

混江龙づ霸主 提交于 2019-12-02 01:28:46

问题


INCLUDE Irvine16.inc

.data
    byteArray   BYTE 6 DUP(?)
    listSize = ($ - byteArray)
    aSum        WORD 0
    soffset = 0
.code
main PROC
    mov     ax, @data
    mov     ds, ax
    mov     cx, listSize
Loop1:
    mov     ax, 0
    movzx   ax, [byteArray + soffset]
    add     aSum, ax
    soffset = soffset + 1
    loop Loop1
    exit
main ENDP
END main

The error I'm getting is error "A2074:cannot access label through segment registers"

I'm trying to use the soffset to loop through the byteArray.


回答1:


I'm not sure what's in Irvine16.inc, but I bet it is saying .model small,... at some point.

If you add

ASSUME DS:_DATA

then your error messages will go away, although I doubt if that's enough to make the program run.


Ok, I've got an idea. I think you should switch to the 32-bit examples. That's a flat model where the segment registers are set up by the OS and not used by programs. I just downloaded the irvine examples and the sample project, which happens to be 32-bits did assemble and run.

In the wierd and twisted world that is x86 machine code, the 16-bit model is quite a bit more complex than the 32-bit model, at least from the point of view of a user program.




回答2:


This error is caused by trying to assemble a DOS program (.model != flat) to a COFF .obj file. Additionally ML.EXE throws error A2006:undefined symbol : DGROUP. The source should be assembled to an old fashion OMF file. Build the file with following command lines:

ml.exe /omf hello.asm
link16.exe hello.obj, hello.exe;

ml.exe is part of the Visual Studio installation. link16.exe is part of Irvine's library suite (" Example programs and link library source code...").



来源:https://stackoverflow.com/questions/1512734/cannot-access-label-through-segment-registers-error-in-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!