Can the following mixture of data into code section be possible??

.code

start:

; ??????????????????????????????????????
invoke MessageBox,0,ADDR txt,ADDR cap,MB_OK

txt db "Hello! It WOrked!!",0
cap db "Yeah!",0

; ??????????????????????????????????????

end start

:stupid:
Posted on 2004-05-28 14:01:09 by telophase
You can have code, data and whatnot in one section.
Just be careful to not execute data ;) and to set section attributes to writable if necessary.
Posted on 2004-05-28 14:04:42 by omega_red
how do i do the above thing i tried compiling the above posted code of mine but cant seem to get it

I get errors while compiling can u elaborate more and post some example code too??
Posted on 2004-05-28 14:07:20 by telophase
I don't use masm - post your errors please.
Posted on 2004-05-28 14:35:27 by omega_red
original code:

code

; ?????????????????????????????????????????????????????????????????????????

start:

; ??????????????????????????????????????
invoke MessageBox,0,ADDR txt,ADDR cap,MB_OK
invoke ExitProcess,0
cap db "Yeah!",0
txt db "Hello! It WOrked!!",0
; ???????????????????????????????????????

end start

errors:
msg_txt.asm(62) : error A2006: undefined symbol : cap
msg_txt.asm(62) : error A2114: INVOKE argument type mismatch : argument : 3
msg_txt.asm(62) : error A2006: undefined symbol : txt
msg_txt.asm(62) : error A2114: INVOKE argument type mismatch : argument : 2
_
Assembly Error
Press any key to continue . . .

I cant seem to get the file assembled itself :confused:
Posted on 2004-05-28 14:40:52 by telophase
Hi telophase,



.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.code

txt db "Hello! It WOrked!!",0
cap db "Yeah!",0

start:
invoke MessageBox,0,ADDR txt,ADDR cap,MB_OK
invoke ExitProcess,0

END start
Posted on 2004-05-28 14:43:37 by Vortex
MASM cannot resolve forward references to data.

Mirno
Posted on 2004-05-28 14:45:09 by Mirno
Thankyou for the code vortex

But that means that i will have to declare all the variables before i call the functions itself eh?

Also i want to modify the variables then i need to make the section writeable? :confused:
Posted on 2004-05-28 14:47:41 by telophase

Hi telophase,



.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.code

txt db "Hello! It WOrked!!",0
cap db "Yeah!",0

start:
invoke MessageBox,0,ADDR txt,ADDR cap,MB_OK
invoke ExitProcess,0

END start



You dont need to have it at the begining .. this is just one solution. The key is to not have your program execute your text strings:



.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.code
start:
invoke MessageBox,0,ADDR txt,ADDR cap,MB_OK

jmp @F
txt db "Hello! It WOrked!!",0
cap db "Yeah!",0
@@:

invoke ExitProcess,0

END start


Regards,
:NaN:
Posted on 2004-05-28 15:03:55 by NaN
If you want to write to section, it must have `writable' bit in section flags or you'll get access violations. Not sure how to do it in masm though.
Posted on 2004-05-28 15:20:52 by omega_red
Hi NaN,

Sorry but your code appears to be not correct:


Assembling: msgbox.asm
msgbox.asm(12) : error A2006: undefined symbol : cap
msgbox.asm(12) : error A2114: INVOKE argument type mismatch : argument : 3
msgbox.asm(12) : error A2006: undefined symbol : txt
msgbox.asm(12) : error A2114: INVOKE argument type mismatch : argument : 2


You should define your variables before referencing them with ADDR.
Posted on 2004-05-28 16:35:07 by Vortex
I supose that offset can calculate forward references?.

By the way, addr is a diferent thing.

Have a nice day or night.
Posted on 2004-05-28 17:29:28 by rea
Hi! NaN,

Your code gives error but when i try it using TASM method in MASM itself i get no errors :confused:

push 0
push OFFSET txt
push OFFSET cap
push 0
call MessageBox


The above code works out fine but then i cant use the invoke syntax:(
Posted on 2004-05-28 22:46:05 by telophase
As opposed to having the data in the code section using jmp @F you can simply place it in an area that will not be executed, for example after ExitProcess or after RET in a procedure or even between procedures...

.386

.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.code
txt db "Hello! It WOrked!!",0
cap db "Yeah!",0

start:
invoke MessageBox,0,offset txt,offset cap,MB_OK

invoke ExitProcess,0


SomeProc proc

push MB_OK
push offset testdata2
push offset testdata1
call MessageBox

ret
testdata1 db "Hello there",0
testdata2 db "How are you",0

SomeProc endp

testdata3 db "Hello there",0
testdata4 db "How are you",0

SomeProc2 proc

invoke MessageBox,0,offset testdata3,offset testdata4,MB_OK

ret
SomeProc2 endp

END start
Posted on 2004-05-28 22:53:39 by donkey
Hey! Donkey,

Tried compiling that code but i get the following errors in the code:
msg_txt.asm(59) : error A2006: undefined symbol : cap
msg_txt.asm(59) : error A2114: INVOKE argument type mismatch : argument : 3
msg_txt.asm(59) : error A2006: undefined symbol : txt
msg_txt.asm(59) : error A2114: INVOKE argument type mismatch : argument : 2
msg_txt.asm(68) : error A2006: undefined symbol : testdata2
msg_txt.asm(68) : error A2114: INVOKE argument type mismatch : argument : 3
msg_txt.asm(68) : error A2006: undefined symbol : testdata1
msg_txt.asm(68) : error A2114: INVOKE argument type mismatch : argument : 2

Backward data is still not working :(
Posted on 2004-05-28 22:57:02 by telophase
Sorry,

I just typed it on the fly, in GoAsm which is what I use it is perfectly OK that way. I changed the code to allow for MASMs problem with forward references.
Posted on 2004-05-28 22:58:25 by donkey
What is GoAsm is it a IDE or something?

Where can i get it?
Posted on 2004-05-28 23:02:15 by telophase
GoAsm is an assembler...

http://www.godevtool.com/

You can use forward references in MASM as long as you don't use INVOKE...

SomeProc proc


push MB_OK
push offset testdata2
push offset testdata1
call MessageBox
;invoke MessageBox,0,offset testdata1,offset testdata2,MB_OK

ret
testdata1 db "Hello there",0
testdata2 db "How are you",0

SomeProc endp


Is just fine, pretty dumb IMHO.
Posted on 2004-05-28 23:03:42 by donkey
But then why is it that MASM has problems compiling it?

And GoAsm dosent have any problems :confused:
Posted on 2004-05-28 23:05:19 by telophase
GoAsm isn't MASM, it handles scoping much better and certainly handles invoke infinitely better. The problem is in the INVOKE macro in MASM, it has many other problems besides just that one, GoAsm does not.
Posted on 2004-05-28 23:07:01 by donkey