MASM32 error A2006, error A2074 and warning A4023

2020-07-27 06:08发布

问题:

I am new to assmebly. I have the following piece of code from the book I am learning form. I downloaded MASM32. My computer is Win7 64bit. I tried to build the following code:

.model small
.stack 100h

.data
a dw 2
b dw 5
sum dw ?

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

mov ax, a
add ax, b
mov sum, ax

mov ax, 4c00h
int 21h

main endp
 end main

Unfortunately, I get the following errors:

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: C:\masm32\test.asm
C:\masm32\test.asm(11) : error A2006: undefined symbol : DGROUP
C:\masm32\test.asm(14) : error A2074: cannot access label through segment registers
C:\masm32\test.asm(15) : error A2074: cannot access label through segment registers
C:\masm32\test.asm(16) : error A2074: cannot access label through segment registers
C:\masm32\test.asm(22) : warning A4023: with /coff switch, leading underscore required for start address : main
_
Assembly Error
Press any key to continue . . .

I have searched about solutions. I could solve the error A2074: by adding ASSUME DS:_DATA before .data line. I took it from this post: Cannot access label through segment registers, error in assembly but unfortunately, the solution does not provide explanations of why and what is this ?

Why these errors appear and how to solve them? I am a newbie and need some details and step by step at the beginning.

回答1:

You need to use the 16 bit Microsoft Segmented Linker to link 16 bit DOS code, NOT the Incremental Linker that comes with MASM32, download from MS: 16 bit Microsoft Segmented Linker 5.60

Unzip to a directory then rename link.exe to something like link16.exe and place that into your /masm32/bin directory. You now can use link16 for 16 bit DOS apps and link for 32 bit apps.

You also need to use the correct command line parameters to Assemble 16bit code, example here: assembly fatal error LNK1190: invalid fixup found, type 0x0001 As you are using a 64 bit OS, you cannot run a 16 bit DOS app natively anymore, you need to use an emulator. I use D-Fend Reloaded.