The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: bf2 on January 22, 2011, 12:10:34 AM

Title: Error A2084: constant value too large
Post by: bf2 on January 22, 2011, 12:10:34 AM
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.
Title: Re: Error A2084: constant value too large
Post by: 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
Title: Re: Error A2084: constant value too large
Post by: bf2 on January 22, 2011, 12:16:57 AM
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.
Title: Re: Error A2084: constant value too large
Post by: dedndave on January 22, 2011, 12:23:45 AM
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
Title: Re: Error A2084: constant value too large
Post by: bf2 on January 22, 2011, 12:26:56 AM
So why can't I move an immediate value to a memory location?
Title: Re: Error A2084: constant value too large
Post by: dedndave on January 22, 2011, 12:29:55 AM
it is a string longer than 4 bytes
Title: Re: Error A2084: constant value too large
Post by: bf2 on January 22, 2011, 12:31:24 AM
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 !
Title: Re: Error A2084: constant value too large
Post by: 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
Title: Re: Error A2084: constant value too large
Post by: bf2 on January 22, 2011, 12:36:55 AM
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.
Title: Re: Error A2084: constant value too large
Post by: dedndave on January 22, 2011, 12:38:24 AM
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