if i want to declare the variables szTITLE and szMSG in code
segement what changes should i have 2 do in  the following program
so that it runs.


;-------working program-------------------------------------------------
.386           
.model flat

EXTRN MessageBoxA:PROC
EXTRN ExitProcess:PROC

lpTITLE EQU OFFSET szTITLE
lpMSG EQU OFFSET szMSG

.data
szTITLE DB "MESSAGEBOX",0
szMSG DB "HELLO WORLD!",0
.code
 
START:
          PUSH 0
          PUSH lpTITLE
          PUSH lpMSG
          PUSH 0
          CALL MessageBoxA
          CALL ExitProcess
END START 
;--------------------------------------------------------
Posted on 2006-05-28 11:12:33 by sihotaamarpal
I don't have Tasm available but here is my guess:


.386?  ?  ?  ?  ?  ?  ? 
.model flat, stdcall

EXTRN MessageBoxA:PROC
EXTRN ExitProcess:PROC

lpTITLE EQU OFFSET szTITLE
lpMSG EQU OFFSET szMSG

.data
szTITLE DB "MESSAGEBOX",0
szMSG DB "HELLO WORLD!",0
.code
?  ? 
START:
?  ?  ?  ?  ?  PUSH 0
?  ?  ?  ?  ?  PUSH lpTITLE
?  ?  ?  ?  ?  PUSH lpMSG
?  ?  ?  ?  ?  PUSH 0
?  ?  ?  ?  ?  CALL MessageBoxA
?  ?  ?  ?  ?  CALL ExitProcess
END START?  ? 


Building the executable:


tasm32?  /ml FileName.asm
ilink32 FileName.obj,,,kernel32.lib


All Credit goes to Vortex over here : http://www.asmcommunity.net/board/index.php?topic=19416.msg149769#msg149769
Posted on 2006-05-28 12:20:07 by JimmyClif
hi JimmyClif
  my ques is not on assembling and linking,mu question is if i want to declare variables in code segment instead of data segment then what should i have 2 change in the code
Posted on 2006-05-28 13:30:36 by sihotaamarpal
Would this work? (I assume that you are using TASM as JimmyClif suggests, so I didnt test it as I don't have TASM)

.386             
.model flat

EXTRN MessageBoxA:PROC
EXTRN ExitProcess:PROC

lpTITLE EQU OFFSET szTITLE
lpMSG EQU OFFSET szMSG

.code
szTITLE:
DB "MESSAGEBOX",0
szMSG:
DB "HELLO WORLD!",0
 
START:
          PUSH 0
          PUSH lpTITLE
          PUSH lpMSG
          PUSH 0
          CALL MessageBoxA
          CALL ExitProcess
END START 


Ossa
Posted on 2006-05-28 13:40:54 by Ossa
sihotaamarpal: just put the variables in ".code" :)

If you want to writable variables in your code section, use the "/link:.text,rwe" linker switch to make your code section read, write, eexecute. Not generally a good idea, but if you insist...
Posted on 2006-05-28 13:44:19 by f0dder
Or, you could simply try like we had to do in old .COM programs.

.code
?  ? 
START:
?  ?  ?  ?  ? JMP NEXTCODE
szTITLE:
?  ?  ?  ?  ?  DB "MESSAGEBOX",0
szMSG:
?  ?  ?  ?  ?  DB "HELLO WORLD!",0

NEXTCODE:
?  ?  ?  ?  ?  PUSH 0
?  ?  ?  ?  ?  PUSH lpTITLE
?  ?  ?  ?  ?  PUSH lpMSG
?  ?  ?  ?  ?  PUSH 0
?  ?  ?  ?  ?  CALL MessageBoxA
?  ?  ?  ?  ?  CALL ExitProcess
END START?  ? 


Raymond
Posted on 2006-05-29 12:10:27 by Raymond

Or, you could simply try like we had to do in old .COM programs.

Which was pretty silly, since you could just place the variables at the end of your program instead, and save the MASSIVE ;) amount of bytes taken by the jump <g>.
Posted on 2006-05-29 12:16:35 by f0dder
ExitProcess requires that an exit code be pushed...

...
push 0 ; exit code
call ExitProcess
Posted on 2006-05-29 13:30:45 by donkey