Don't understand why mov instruction gives an invalid operand error

Started by mrBean, November 30, 2013, 09:42:00 PM

Previous topic - Next topic

mrBean

Hi,  I am learning Assembly language using Jeff Dunterman's Assembly Language Step by Step book. 

I am trying out a 16 bit real mode flat model assembly program using MASM32 in Win XP.

The code is:

.286
.MODEL TINY
.DATA               ; Initialised data section
eatmsg   db  "Eat at Joe's!", 13, 10, "$"    ;message to display             

.CODE               ; Code section
start:

    mov dx, eatmsg  ; Mem data ref without [] loads the address
    mov ah, 9       ; Function 9 displays text to standard output
    int 21H         ; Call DOS

    mov ax, 04C00H  ; DOS function to exit the program
    int 21H         ; Return control to DOS


end start

When I assembled the file, I got the following message:
error A2070: invalid instruction operands

The error refers to the mov dx, eatmsg statement.  What is wrong with the operand that causes the error message to appear?

Also, there is a warning:
warning A4023: with /coff switch, leading underscore required for start address : start

I saw other code examples which use the start label so I am not sure what is the cause of the warning?


dedndave

    mov dx, offset eatmsg
without the "offset" operator, it tries to load the first WORD of the string into DX
because the string is defined as BYTE type and DX is a WORD - the error occurs

dedndave

QuoteAlso, there is a warning:
warning A4023: with /coff switch, leading underscore required for start address : start

I saw other code examples which use the start label so I am not sure what is the cause of the warning?

it's odd that i don't recall seeing that one   :biggrin:
as it happens, i have always used a "_main" PROC as the entry point (an old C compiler standard)

        .MODEL  Tiny
        .386
        OPTION  CaseMap:None

;####################################################################################

        .CODE

;************************************************************************************

        ORG     100h

_main   PROC    NEAR

        mov     dx,offset s$Msg
        mov     ah,9
        int     21h

        mov     ax,4C00h
        int     21h

_main   ENDP

;####################################################################################

s$Msg   db 'Hello World !',0Dh,0Ah,24h

;####################################################################################

        END     _main


i have also never used a .DATA section with a TINY model program
but - that is nice, if it works

when it's all said and done, a couple rules for a TINY model are:
all code and data must fall within a single 64 KB segment
the program loader uses the first 256 bytes of the segment for the PSP, Program Segment Prefix
so, the first byte of the .COM program must be ORG'ed at 100h
and it is always where execution begins

it's likely that the linker combines .DATA at the end of the code segment

FORTRANS

Hi,

   Doing a search on "Jeff Dunterman's Assembly Language Step
by Step book.", I got a description that says it uses the NASM
assembler.  That makes your comment "; Mem data ref without
[] loads the address" correct.  However the error message
numbers seem to imply you are trying to use MASM as your
assembler.  So you would have to use OFFSET as Dave says.

   NASM and MASM use different, though similar, syntax.

Regards,

Steve N.

dedndave

oh...
and, use the /COFF switch when assembling 32-bit code
this is 16-bit code - you want the /OMF switch (which is the default, so no switch)
that also means you need to use a 16-bit linker
in the masm32 pacakge, i believe it's named Link16.exe