News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

LES question ... assembly error ...

Started by m7xtuf, June 22, 2010, 12:56:44 AM

Previous topic - Next topic

m7xtuf

Hi there,

   I got an error when assembling ... but no idea why ???  Please copy this code on your editor and try ... THANX !!!

-------------------------------------------------------------------------
.data

Array STRUCT
data DW 9
Array ENDS

g_Array Array {}

g_ArrayPtr DD g_Array

String db 'Value = %i', 10, 0

.code

Start:

MOV EBX, 0
LES BX, g_ArrayPtr

MOV AX, ES:[BX].Array.data     <-- error !!!

invoke  crt_printf, addr String, EAX

ret

end         Start
-------------------------------------------------------------------------
 
I have tried replacing with "MOV AX, ES:[EBX].Array.data" to pass the error but the program crashed !!!

HELP needed ... THANX !!!


clive

Decide if you want to do 16-bit code, or 32-bit code, because they don't mix well


  LEA  EBX, g_ArrayPtr

  MOVZX  EAX, [EBX].Array.data

  invoke  crt_printf, addr String, EAX
It could be a random act of randomness. Those happen a lot as well.

dedndave

#2
to expand on what Clive was saying....
the ES segment register may need to be set for a 16-bit (segmented) program
16-bit programs can only address segments of 64 Kb with one segment register value
but, for 32-bit code, ES is usually left alone, as you can address 4 Gb linear address space
invoke'ing CRT functions, as well as windows API functions, is for 32-bit applications
they may not be used in 16-bit programs, which normally access system services via INT 21h or one of the BIOS INT's

at the end of the day, you are trying to mix apples and oranges   :P

clive

        .386
        .MODEL FLAT, STDCALL

        include \masm32\include\msvcrt.inc
        includelib "\masm32\lib\msvcrt.lib"

        .DATA

Array   STRUCT
data    DW      9
Array   ENDS

g_Array Array {}

g_ArrayPtr DD g_Array

String  DB 'Value = %i', 10, 0

        .CODE

Start:

; So either

        LEA     EBX, g_ArrayPtr ; Address of pointer
        MOV     EBX,[EBX]       ; Load pointer

; or    MOV     EBX,[g_ArrayPtr] ; Load address at address

        MOVZX   EAX, [EBX].Array.data

        invoke  crt_printf, addr String, EAX

        ret

        end         Start


C:\MASM>ml -coff -Fl test24.asm -link /SUBSYSTEM:CONSOLE
Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

Assembling: test24.asm
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/SUBSYSTEM:CONSOLE
"test24.obj"
"/OUT:test24.exe"

C:\MASM>test24
Value = 9
It could be a random act of randomness. Those happen a lot as well.