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:
.code
start:
; ??????????????????????????????????????
invoke MessageBox,0,ADDR txt,ADDR cap,MB_OK
txt db "Hello! It WOrked!!",0
cap db "Yeah!",0
; ??????????????????????????????????????
end start
:stupid:
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.
Just be careful to not execute data ;) and to set section attributes to writable if necessary.
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??
I get errors while compiling can u elaborate more and post some example code too??
I don't use masm - post your errors please.
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:
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:
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
MASM cannot resolve forward references to data.
Mirno
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:
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:
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:
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.
Hi NaN,
Sorry but your code appears to be not correct:
You should define your variables before referencing them with ADDR.
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.
I supose that offset can calculate forward references?.
By the way, addr is a diferent thing.
Have a nice day or night.
By the way, addr is a diferent thing.
Have a nice day or night.
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:(
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:(
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
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 :(
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 :(
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.
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.
What is GoAsm is it a IDE or something?
Where can i get it?
Where can i get it?
GoAsm is an assembler...
http://www.godevtool.com/
You can use forward references in MASM as long as you don't use INVOKE...
Is just fine, pretty dumb IMHO.
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.
But then why is it that MASM has problems compiling it?
And GoAsm dosent have any problems :confused:
And GoAsm dosent have any problems :confused:
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.