flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > if and else again

Author
Thread Post new topic Reply to topic
uri



Joined: 09 Apr 2004
Posts: 43
Location: L'viv, Ukraine
uri 06 May 2004, 11:46
Good day, look this

program:
Code:
format MS COFF
macro    select  a,b,c
{
if b > c
   a equ b
else
   a equ c
end if
}

public    main as '_main'
main:
  select      myvar,3,7
mov        eax,myvar
  select   myvar,6,4
mov        eax,myvar
  ret
    

result:
Code:
B8 07000000  mov     eax, 7
B8 04000000  mov     eax, 4
C3                 retn
    

why mov eax,4 ? must be mov eax,6

i want to use equ, no = , because i want like this

select myvar, var1, var2

it's possible?

thanks
Post 06 May 2004, 11:46
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 06 May 2004, 13:05
Weird, there is a problem with macro substitution. "if-else" does it right.
I'm puzzled ¿?

Compiling this:
Code:
macro select a,b,c
{
if b > c
   display 'b > c = TRUE',0Dh,0Ah
   display 'before a,b,c = ',a+30h,', ',b+30h,', ',c+30h,', ',0Dh,0Ah
   a equ b
   display 'after equ a,b,c = ',a+30h,', ',b+30h,', ',c+30h,', ',0Dh,0Ah
else
   display 'b > c = FALSE',0Dh,0Ah
   display 'before a,b,c = ',a+30h,', ',b+30h,', ',c+30h,', ',0Dh,0Ah
   a equ c
   display 'after equ a,b,c = ',a+30h,', ',b+30h,', ',c+30h,', ',0Dh,0Ah
end if
}
myvar equ 0
display 'myvar = ',myvar+30h,0Dh,0Ah
select myvar,3,7
display 0Dh,0Ah,'myvar = ',myvar+30h,0Dh,0Ah
select myvar,6,4
display 0Dh,0Ah,'myvar = ',myvar+30h,0Dh,0Ah
myvar equ 6
display 0Dh,0Ah,'myvar = ',myvar+30h
    

Will result in:
Code:
myvar = 0
b > c = FALSE
before a,b,c = 3, 3, 7, 
after equ a,b,c = 7, 3, 7, 

myvar = 7
b > c = TRUE
before a,b,c = 7, 6, 4, 
after equ a,b,c = 6, 6, 4, 

myvar = 4

myvar = 6    
Post 06 May 2004, 13:05
View user's profile Send private message Yahoo Messenger Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 06 May 2004, 13:32
maybe it's because IF's are processed at assembly stage, so they will be calculated *after* equ's.
Post 06 May 2004, 13:32
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8394
Location: Kraków, Poland
Tomasz Grysztar 06 May 2004, 14:37
See the third question in the FAQ.


Last edited by Tomasz Grysztar on 11 Jun 2005, 18:40; edited 1 time in total
Post 06 May 2004, 14:37
View user's profile Send private message Visit poster's website 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.