Search code examples
assemblymasmirvine16

Cannot access label through segment registers, error in assembly


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.


Solution

  • 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.