flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Imagist 23 Aug 2004, 03:51
Oo! Interesting question!
*waits for someone to answer it, since he doesn't know* |
|||
![]() |
|
crc 23 Aug 2004, 04:10
Code: function1: jmp .over_data .a dd 0 .b dd 1 .over_data: mov eax, [.a] mov ebx, [.b] ret function2: jmp .over_data .a dd 3 .b dd 4 .over_data: mov ecx, [.a] mov edx, [.b] ret And so on. This has worked in all my tests, so I see no reason not to make use of it. As long as the variable name starts with '.' it should work just fine. |
|||
![]() |
|
Dragontamer 23 Aug 2004, 12:12
Wow, self modifying code.
![]() Thats not how you do that... Unless you have SMC, windows or linux will surely crash your program. You cannot treat code segment stuff as data unless you make SMC availiable for your program. Now the real method is much more complex, and manipulates the stack in a very hard way... Code: function1: push ebp mov ebp, esp sub esp, 32; size of bytes you are allocating. I just allocated 32 bytes virtual at esp ;vars here max 32 bytes because i only added 32 end virtual ;rest of function mov esp, ebp pop ebp ret Oh, and you can't "initialize" the variables. It always has to either be rb or db ? (edit note. I said add esp,32?!?!?? Stupid me, i forgot that the stack is upside down) Last edited by Dragontamer on 23 Aug 2004, 13:23; edited 1 time in total |
|||
![]() |
|
crc 23 Aug 2004, 13:05
Quote: Wow, self modifying code. Hmm, I always use a writeable code segment, so I tend to forget that... |
|||
![]() |
|
vid 23 Aug 2004, 20:11
I think he wanted this (with usage of macros)
Code: DEBUG = 1 ;procedure name proc a ;list of arguemnt follows var1 dd 0 var2 dd 0 ;conditionally define data if DEBUG = 1 debugvar1 dd 0 debugvar2 dd0 end if ;and here goes the code enter ... And when you are done debugging, you change first line to "DEBUG = 0". is this what you wanted? (to conditionally define data?) |
|||
![]() |
|
Worr 25 Aug 2004, 00:51
All of those are what I wanted. I'm not sure I described it well at all the first time around.
The Jump method by crc is all that I needed, but the use of the virtual thing (for lack of better words) was going to be my next question. The method by vid will be helpful too, since it does what I want, just better and makes more sense, to me atleast. Thanks ![]() Worr |
|||
![]() |
|
Zetus 25 Aug 2004, 07:21
locals not need to avoid by jump. Always in stack. If we have used this variable in proc, it reserves stack space, if not used - no reserve.
proc Xe, enter mov eax,[.A] return .A dd 0 .B dd 0 ".B" variable not used, and only 1 dd reserved in stack. Compiler "forgots" your locals after you define a next proc. |
|||
![]() |
|
vid 25 Aug 2004, 18:21
zetus, you're wrong. What you did is placing variables in code, which also requires to have code segment writeable. Absolutely bad thing to do unless you know what you are doing.
|
|||
![]() |
|
crc 25 Aug 2004, 22:01
Why is it considered bad to have a writeable code segment? I understand that some security risks can arise, but that's the only downside I see to it.
|
|||
![]() |
|
Dragontamer 26 Aug 2004, 02:27
Ditto. But having data that close to the code is bound to screw up your cache memory.
|
|||
![]() |
|
pelaillo 26 Aug 2004, 04:03
I prefer to avoid having data on code segment unless strictly needed.
|
|||
![]() |
|
Zetus 26 Aug 2004, 09:44
We discuss a LOCALS,not?
In TASM terms, It's must be in stack, no difference where I place it in text. Most of locals we don't need out of procedure... Or we need two types of variables: loacals WITH real bytes reserve, and locals, temporary existing in stack,while in proc. No check by myself )) |
|||
![]() |
|
Octavio 26 Aug 2004, 16:25
[quote="Zetus"]We discuss a LOCALS,not?
No only stack variables are locals you are talking about what in 'c' language is called 'static', but you place it in code segment instead of data segment, that is useless and the code can not be shared in a multithread program. |
|||
![]() |
|
vid 26 Aug 2004, 20:33
also recursion is impossible, code portability is reduced (when someone place it in nonwritable space), it slows down code greatly, doesn't work with CS != DS (ok, this one isn't that serious), and also stack variables are usually faster than one in data (note mentioning those in code) because stack is usually cached.
|
|||
![]() |
|
Mac2004 30 Aug 2004, 10:52
I have been using this local variable method for quite long time and it works. Jmp instruction must be used due to cpu treating our local variables as instructions. I mainly do plain binary coding(=OS development) without need to worry about code and data segments. Everything has worked neatly so far.
![]() Worr, This method really works and I would recommend using it. It's simple to use!! ![]() regards, Mac2004 |
|||
![]() |
|
vid 30 Aug 2004, 11:31
yes it works, but is less effective and more dangerous, as i have said, you must know what you are doing.
|
|||
![]() |
|
Mac2004 30 Aug 2004, 12:06
Quote:
That's right vid!! True assembler programmer needs to know he's/she's doing. Not knowing can cause quite a mess eg. destroying hard drive partitition tables. regards, Mac2004 |
|||
![]() |
|
vid 30 Aug 2004, 18:49
well, then we agreed.
btw, i am using variables in code too, but don't tell anyone... I just didn't want to learn others such things until they understand it. |
|||
![]() |
|
Worr 30 Aug 2004, 21:57
Yeah, I know how it works and it's risks, but I know enough of what I'm doing, so it works for me. I'll use it for quick simple things, but I know that it isn't the proper way.
Worr |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.