flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > assign value of register to an constant

Author
Thread Post new topic Reply to topic
marcinzabrze12



Joined: 07 Aug 2011
Posts: 61
marcinzabrze12 14 Mar 2012, 18:46
Is possible to assign a value of register (value at now) to an constant ?
While i try something like:
Code:
macro  const  ConstName, reg
{
    ConstName   equ reg 
}

    


Then ConstName is changed every time when "reg" is changed.
Compiller dont let me do:
Code:
macro const  ConstName, reg 
{
       ConstName  =   reg
}

; now when i use in code:

      const      x, eax;   error:  "invalid value"

     
    


Someone can tell me what is wrong ? Sorry for my english.
Post 14 Mar 2012, 18:46
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20533
Location: In your JS exploiting you and your system
revolution 14 Mar 2012, 19:25
No macro is required.
Code:
x equ eax    
Post 14 Mar 2012, 19:25
View user's profile Send private message Visit poster's website Reply with quote
marcinzabrze12



Joined: 07 Aug 2011
Posts: 61
marcinzabrze12 14 Mar 2012, 20:11
It isn't work corectly because if you change EAX then X will be change too.
I want to have a constant value of register at current time.

Code:

;====================================================
macro   ShowV  arg   {
           push   eax ebx ecx edx esi edi
           local buffer
           jmp   @f
                   buffer         db  20 dup (0)
@@: cinvoke      wsprintf, buffer, '%d', arg
    invoke       MessageBox, 0, buffer, 'ShowValue', 0
    pop          edi esi edx ecx ebx eax}  
;====================================================
start:

        mov        eax, 100 ; load value for test it
        x          equ  eax
        ShowV      x        ;  its display 100 - everything ok now

        inc        eax      ; we change the EAX 
        ShowV      x        ; its display  101 because eax is changed. i nedd to 
                            ; have  x = 100 at this line.
    
Post 14 Mar 2012, 20:11
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20533
Location: In your JS exploiting you and your system
revolution 14 Mar 2012, 20:22
The CPU does not have a register named x (which is what you want to do here) so what you really want is to define a memory variable to save the value of eax so you can retrieve it later.
Code:
x dd ?
;...
mov eax,100
mov [x],eax
ShowV [x]
inc eax
ShowV [x]    
Post 14 Mar 2012, 20:22
View user's profile Send private message Visit poster's website Reply with quote
marcinzabrze12



Joined: 07 Aug 2011
Posts: 61
marcinzabrze12 14 Mar 2012, 21:01
Yea. Sorry for a problem. Now i understand why it is impossible ...please forgot about it.
Thanx for help.
Post 14 Mar 2012, 21:01
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.