Cannot access label through segment registers, error in assembly
Question
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.
OTHER TIPS
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...").