News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

segment size

Started by mabdelouahab, August 01, 2016, 04:31:34 PM

Previous topic - Next topic

mabdelouahab


MysSgment segment public 
Var01 dd 00
MysSgment ends
...
MysSgment segment public 
Var022 dd 03
MysSgment ends


How can I get the size of  MysSgment  at executing (not at assembling), Or at least, how can I limit the size of MysSgment 

jj2007

#1
mov eax, offset var1  ; in segment 1
sub eax, offset var2  ; in segment 2

Have a look at it in the debugger, though. Normal segment size is 4096 512 bytes, but linkers can merge segments. Depends on what you really want to achieve...

nidud

#2
deleted

mabdelouahab

Thank you jj2007, nidud
And these two code (X86 and X64) .
But the 64 version does not accept "OFFSET _INIT",also does not accept "SUB RAX,OFFSET __Var_INIT ", Also you should add ".Code" if you are in the CODE Segment
32 bit code:
Quoteinclude masm32rt.inc
   _INIT      SEGMENT DWORD ALIAS('MySegment')
      __Var_INIT db 'Hi Is '
   _INIT      ENDS
   _INITEND   SEGMENT DWORD ALIAS('MySegment') 
      __Var_INITEND   db 0,'signature'
   _INITEND   ENDS
   _INIT      SEGMENT  DWORD ALIAS('MySegment')
      db 'Me'
   _INIT      SEGMENT 

.code
Start:

   printf("[%s] \n",offset __Var_INIT)

   mov eax,OFFSET _INITEND
   sub eax,OFFSET _INIT
   printf("[%d] \n",eax)

   mov eax,OFFSET __Var_INITEND
   sub eax,OFFSET __Var_INIT
   printf("[%d] \n",eax)

   _INIT      SEGMENT  DWORD ALIAS('MySegment')
      db ' Masm32.'
   _INIT      SEGMENT 

   inkey
   exit
end Start
Quote[Hi Is Me Masm32.]
[18]
[16]
Press any key to continue ...


X64 code:

Quote
include \masm64\include\masm64rt.inc

   _INIT      SEGMENT DWORD ALIAS('MySegment')
      __Var_INIT db 'Hi Is '
   _INIT      ENDS
   _INITEND   SEGMENT DWORD ALIAS('MySegment') 
      __Var_INITEND   db 0,'signature'
   _INITEND   ENDS
   _INIT      SEGMENT  DWORD ALIAS('MySegment')
      db 'Me'
   _INIT      SEGMENT 

.data
      cfmstr   db   '[%s] \n',0
      cfmdwd   db   '[%d] \n',0
.code

main proc <4>
   sub rsp,40
   invoke _cprintf ,&cfmstr,offset __Var_INIT

;   mov rax,OFFSET _INITEND ;------------> error A2148:invalid symbol type in expression : _INITEND
;   mov rcx,OFFSET _INIT  ;------------> error A2148:invalid symbol type in expression : _INIT 
;   sub rax,rcx
;   invoke _cprintf ,&cfmdwd,rax

   mov rax,OFFSET __Var_INITEND
   mov rcx,OFFSET __Var_INIT
   sub rax,rcx
   invoke _cprintf ,&cfmdwd,rax

   invoke ExitProcess,0
   _INIT      SEGMENT  DWORD ALIAS('MySegment')
      db ' Masm64.'
   _INIT      SEGMENT 

   .code
main endp
end

Quote[Hi Is Me Masm64.] \n[16] \n

jj2007

Yes, in x64 you need to use lea rax, somevar

mabdelouahab

Quote from: jj2007 on August 02, 2016, 04:03:12 AM
Yes, in x64 you need to use lea rax, somevar
The same thing
Quote
   lea rax, _INITEND ; ---- error A2148:invalid symbol type in expression : _INIT

jj2007

Try with the name of a variable, not with a segment name.

mabdelouahab

Quote from: jj2007 on August 02, 2016, 07:44:57 AM
Try with the name of a variable, not with a segment name.
I did that in X64 code

mineiro

I think you can find some conflits but you can do that using labels.
To ml you need insert '.386' on first line and 'end start' at end of file to assemble fine.
to ml64  you need insert 'end' at end of file.

MyDataSegment segment para public "DATA"
datastart label dword
;datastart:
      __Var_INIT db 'Hi Is '
MyDataSegment ends
MyInitSegment segment para public "INIT"
      __Var_INITEND   db 0,'signature'
MyInitSegment ends
MyDataSegment segment para public "DATA"
      db 'Me'
MyDataSegment ends

codeSegment segment para public "CODE"
Start:
   mov eax,OFFSET __Var_INITEND
   sub eax,OFFSET __Var_INIT

MyDataSegment segment para public "DATA"
      db ' Masm32.'
dataend label dword
;dataend:
MyDataSegment ends
mov eax,offset dataend
sub eax,offset datastart
mov ecx,dataend-datastart
cmp eax,ecx
codeSegment ends
I'd rather be this ambulant metamorphosis than to have that old opinion about everything