News:

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

Error A2084: constant value too large

Started by bf2, January 22, 2011, 12:10:34 AM

Previous topic - Next topic

bf2

I have this assembly-time error.

Really simple piece of code:
.386
.model flat,stdcall
option casemap:none

include io.h
include \masm32\include\masm32rt.inc

.data
caption  byte "Result",0

number1 word 500
number2 word 12

result byte 40 DUP(?)

.code
start:
mov ax, number1
imul number2
jo Overflow
mov result, "No overflow"
invoke MessageBox, NULL, addr result, addr caption, MB_OK
jmp Continue

Overflow:
mov result, "Overflow"
invoke MessageBox, NULL, addr result, addr caption, MB_OK

Continue:
invoke ExitProcess, NULL

end start


It gives me two of these errors, on the lines where I am moving a string to 'result'. I have allocated 40 bytes for 'result', so cannot understand why the string doesn't fit there.

Many thanks in advance.

dedndave

take this line out
include io.h

you can also take these lines out
.386
.model flat,stdcall
option casemap:none

masm32rt.inc takes care of them
you should look inside masm32rt.inc so you know what is in there   :U

bf2

Quote from: dedndave on January 22, 2011, 12:13:29 AM
take this line out
include io.h

you can also take these lines out
.386
.model flat,stdcall
option casemap:none

masm32rt.inc takes care of them
you should look inside masm32rt.inc so you know what is in there   :U

Done those but still the same.

Thanks a lot for your quick response BTW.

dedndave

also - these lines just won't do   :bg
mov result, "No overflow"
mov result, "Overflow"


try this...
include \masm32\include\masm32rt.inc

.data
caption  byte "Result",0

number1 word 500
number2 word 12

String1 db 'No '
String2 db 'Overflow',0

.code
start:
mov ax, number1
imul number2
mov ecx, offset String2
jo Continue

mov ecx, offset String1

Continue:
invoke MessageBox, NULL, ecx, addr caption, MB_OK
invoke ExitProcess, NULL

end start

bf2

So why can't I move an immediate value to a memory location?

dedndave


bf2

Quote from: dedndave on January 22, 2011, 12:29:55 AM
it is a string longer than 4 bytes


Sorry if I am being thick, but I allocated 40 bytes for the string, and both "overflow" and "Not overflow" are surely less than 40 bytes, right? I even tried with 120 bytes !

dedndave

you can only move a single byte, word, or dword by immediate to memory
you could move 4 bytes as a string, because it is the same as moving a dword
have a look at the code i posted - much more efficient, anyways

bf2

Quote from: dedndave on January 22, 2011, 12:33:15 AM
you can only move a single byte, word, or dword by immediate to memory
you could move 4 bytes as a string, because it is the same as moving a dword
have a look at the code i posted - much more efficient, anyways

OK, got it. Even if I have allocated 100 bytes for a variable, when moving an immediate value I can only move 1 byte.

Many thanks. It's clear now.

dedndave

no - you can move 1, 2, or 4 bytes
mov dword ptr Result,"Text"
mov word ptr Result,"Te"
mov byte ptr Result,"T"

are all valid, although the strings will be backwards   :bg