Reset Global vars to original values - Any Proper way to do this ?

Started by Rainstorm, April 22, 2008, 02:29:34 AM

Previous topic - Next topic

Rainstorm

Hi,
  after the end of my code sometimes.. I loop it to the beginning. When I do this I need all the declerations in the .data section (and .data?) sections to be reset to their original values like as if I was running the application anew. - So far i've been manually resetting the variables in my code which can be a headache, figure which variables ned to be reset etc.... & I don't know what to do about declerations like varr 10 dup (0)

Is there some straight way i could reset all variables/declerations to their original values ? - could i put a label before the .data section & loop back to that label ?

Would appreciate any suggestions as this would be a big help!!

Thankyou

Rainstorm
-

hutch--

Yes,


mov myglobal, 0


The basics are that the .DATA section is writable so the if original value get changed you need to change them back again if you need them.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

sinsi

At the start of your program, allocate enough memory to hold the .data section and back it up to that memory.
Then the first thing you do in your loop is copy it back over the .data section. For the .data? section, just fill it with 0's.

.data
data_start label
;all your vars here
data_end label
.data?
udata_start label
;all your vars here
udata_end label

.code
start:
;allocate memory - length=data_end-data_start
;copy length bytes from data_start to the new memblock
your_loop:
;copy length bytes from memblock to data_start
;zero memory from udata_start to udata_end
;your code here
  jmp your_loop
Light travels faster than sound, that's why some people seem bright until you hear them.

Rainstorm

thanks for the replies guys...just wanted to confirm that there wasn't any such command around that reset the whole .data section.

hutch wrote..
Quotemov myglobal, 0
The basics are that the .DATA section is writable so the if original value get changed you need to change them back again if you need them.

Hutch that is what i've been doing till now.

sinsi wrote..
QuoteAt the start of your program, allocate enough memory to hold the .data section and back it up to that memory.
Then the first thing you do in your loop is copy it back over the .data section. For the .data? section, just fill it with 0's.
... Thats a great idea sinsi.. makes it much simpler!!  :U
i don't know how exactly to get the pointer to the start of memory in the .data section. & how to know where it ends.

-

hutch--

There is a trick to it, the first member in the .DATA section is the start adress, the end of the last member is the end address. make an empty variable at the end as the end marker then get the offset of both. Subtract the start from the end and you have the length.

Something like this.


.DATA
  item1 dd 1234
  ; all the rest you need.
  lastitem dd 0  ; the end marker.


Subtract item1 from lastitem and you have the length to copy.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Rainstorm