Assemble Error ... don't understand why ...

Started by m7xtuf, February 10, 2010, 11:48:40 PM

Previous topic - Next topic

m7xtuf

Hi there,

   I have an assemble error but I have no idea why ... maybe all you experienced programmer can help me ...  With below's code, I got the error "cannot use 16-bit register with a 32-bit address" on the last line.  I am trying to copy the data from Array[] to AX register.

   Help !!!

----------------------------------------------------------------------


.data

Array       dw      25, 169, 144, 9, 49, 144
Count       dw      0

.code

start:

            lea     BX, Array
            mov     SI, Count
            add     SI, SI

            inc     Count

            mov     AX, [BX][SI]


Added code tags



MichaelW

The error message means just what it says. For 32-bit code addresses are 32-bit values, so indirect memory operands must use 32-bit registers. This code will assemble without error:

            lea     EBX, Array
            movzx   ESI, Count
            add     ESI, ESI
            inc     Count
            mov     AX, [EBX][ESI]


But in 32-bit code it would make more sense to define Count as a DWORD, and probably also Array. And since in 32-bit code indirect memory operands can include a scaling factor (of 1, 2, 4, or 8) you can avoid having to scale ESI separately. So the code could then be:

            lea     EBX, Array
            mov     ESI, Count
            inc     Count
            mov     EAX, [EBX+ESI*4]

eschew obfuscation

m7xtuf

Thanx ... but is there a way to keep my code in 16-bit instead of 32-bit ...

redskull

Quote from: m7xtuf on February 11, 2010, 12:30:46 AM
Thanx ... but is there a way to keep my code in 16-bit instead of 32-bit ...

Use the 16-bit linker, and check out the 16-bit subfourm.  More specifically, use the small (or tiny) model directive.  Also, if you are more interesting in learning than producing code, things like emu8086 offer easy ways to get started.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government