News:

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

problems with this code..

Started by Rainstorm, October 22, 2006, 05:01:52 PM

Previous topic - Next topic

Rainstorm

problem with this code..

.data
linne1 db "Test run..",0
mov ecx, [linne1]


i get the error - Invalid instruction operands for the line;   mov ecx, [linne1]
am thinking that the address of linne1 (ie [linne1])is a 32 bit value
so the data sizes match..
could someone elaborate on that..

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

the other prob is,..i changed the datatype to dword..
.data
linne1 dd "test run..",0
.code
mov ecx, [linne1]


then i get this..
error A2084: constant value too large for the line;  linne1 dw "test run..",0

i can't make sense of that one..

thanks

Rainstorm

trodon

hi Rainstorm,
try with mov ecx, offset linne1

Vortex

Rainstorm,

Trodon is right, you should use the OFFSET operator to point linne1 :

.data
linne1 db "test run..",0
.code
mov ecx,OFFSET linne1

Rainstorm

trodon, vortex....thanks that worked!

just out of curiosity sake...do you know the reason for the 2nd error msg ?

ty
Rainstorm

trodon

Quotejust out of curiosity sake...do you know the reason for the 2nd error msg ?

.data
linne1 dd "test run..",0
.code
mov ecx, [linne1]


try like this

.data
linne1 db "test run..",0
.code
mov ecx offset linne1

thats not error, its only bad tuping  :U


Rainstorm

are there any general situations where i need to us 'offset'     rather than  [variablename] to get the address ?

trodon

Quote from: Rainstorm on October 23, 2006, 07:28:49 PM
are there any general situations where i need to us 'offset'     rather than  [variablename] to get the address ?

sorry but i dont understand you question  :dazzled:

MichaelW

Rainstorm,

For MASM "variablename" and "[variablename]" both return the value of the variable. To get the address of the variable you must use OFFSET or LEA.

.586
.model flat,stdcall
option casemap:none

include \GeneSys\include\windows.inc
include \GeneSys\include\kernel32.inc
include \GeneSys\include\user32.inc
include \GeneSys\include\msvcrt.inc
includelib \GeneSys\lib\kernel32.lib
includelib \GeneSys\lib\user32.lib
includelib \GeneSys\lib\msvcrt.lib
include \GeneSys\macros\macros.asm

.data

    myvar dd 123h

.code
start:

    mov eax, myvar
    invoke printf,chr$("%Xh%c"),eax,10
    mov eax, [myvar]
    invoke printf,chr$("%Xh%c"),eax,10
    mov eax, offset myvar
    invoke printf,chr$("%Xh%c"),eax,10
    lea eax, myvar
    invoke printf,chr$("%Xh%c"),eax,10

  @@:
    invoke _kbhit
    test eax, eax
    jz @B

    invoke exit

end start


123h
123h
403000h
403000h
eschew obfuscation

gabor

Hi!

For the sake of completeness I'd like to mention that there was a second question too:
Quote from: Rainstorm on October 22, 2006, 05:01:52 PM

linne1 dd "test run..",0

error A2084: constant value too large for the line; linne1 dw "test run..",0

This is not a difficult problem. :U Strings can be defined like you did, you put text between quotation marks (like your "test run.."). The data type used for strings is byte, so the correct declaration is your first one:
Quote from: Rainstorm on October 22, 2006, 05:01:52 PM

.data
linne1 db "test run..",0


For other data types, like word, dword, qword you can define a string only that big that fits into that data type. So for words it is a 2-character string, for dwords it is a 4-character string. Like

.data
text1 dw 'AB'
text2 dd 'ABCD'

The reason for the error was that the size of your linnie string is 10 bytes, that is a constant to large for a dword...

Greets, Gábor

PBrennick

It is interesting to note that DW and DD do not function in the same manner as DB.  If they did, you would be able to chain words and dwords in the same way that you can chain bytes. You cannot do the following:

testit dd 'abcdefgh'

but you can do this:

testit dd 'abcd'
        dd 'efgh'

which accomplishs the same thing, testit can be manipulated as if dwords are chained. So some of the limitations of the assembler have work-arounds.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Rainstorm

MichaelW wrote..
QuoteFor MASM "variablename" and "[variablename]" both return the value of the variable. To get the address of the variable you must use OFFSET or LEA..
Thanks for clearing that up..I wasn't aware of it.

Regards

Rainstorm.

-

Rainstorm

hi..

Paul & gabor..that made things much more clear..thanks.

Rainstorm

gabor

Hello!

Quote from: PBrennick on October 24, 2006, 05:18:58 PM
but you can do this:

testit dd 'abcd'
        dd 'efgh'
which accomplishs the same thing, testit can be manipulated as if dwords are chained. So some of the limitations of the assembler have work-arounds.

This works too: testit dd 'abcd','efgh'.

Important difference between db 'abcd' and dd 'abcd' is that in the 2nd case the pattern stored in the memory is reversed!
So

.data
bTestit1 db 'abcd'
bTestit2 db 'dcba'
dwTestit dd 'abcd'

.code
mov eax,dword ptr bTestit1
cmp eax,dwTestit  ; this will be false

mov eax,dword ptr bTestit1
cmp eax,dwTestit  ; this will be true


Greets, Gábor

Rainstorm

..get the picture..

ty.... :)

Rainstorm