I've been trying to make a macro that calculates something and returns it eax, like

calc 3,+,4,*,2

but I haven't been able to get the signs and other stuff work right
Posted on 2003-04-12 18:33:17 by CyberGuy
What exactly do you want such macro to do? After reading your post I've got an impression that you want to do something like mov eax,3+4*2, but that makes no sense.
Posted on 2003-04-13 10:55:28 by Tomasz Grysztar
Maybe, "calc 3,+,4,*,2" would generate:
mov eax, 2

mov edx, 4
mul edx
mov edx, 3
add eax, edx
...? The numbers can be replaced with an register or memory location as well: calc , +, , *, ebx. Seems like all kind of fun could be had with such a macro. :) calc c, +, b, *, x, +, a, *, x, ^, 2
Posted on 2003-04-13 12:07:22 by bitRAKE
I know that stuff like 3+4*2 can be preprocessed but I want the macro to accept variable values too, like if I did calc ,+,2,*,3 or something like that. It would be useful because I have to do alot of calculations and it gets a bit confusing when you have alot in asm. If only there was some directive like next or prev that allowed you to get the next argument and the previous one it would be easy to make it then (for infinite arguments).
Posted on 2003-04-13 12:17:19 by CyberGuy
Here's what I just made so far:

macro calc
{
common
local ..flag
flag equ ..flag
flag = 0
forward
if num = '+'
flag = 1
else if num = '-'
flag = 2
else if num = '*'
flag = 3
else if num = '/'
flag = 4
else
if flag = 0
mov eax,num
else if flag = 1
add eax,num
else if flag = 2
sub eax,num
else if flag = 3
mov ebx,num
mul ebx
else if flag = 4
xor edx,edx
mov ecx,num
div ecx
end if
end if
}

This kind of works but it doesn't follow order of operations and since the if statement is preprocessed, it doesn't allow me to input variables. Is there anyway to check if an argument is a variable or not?

It can do things like calc 2,'+',3,'-',5
Posted on 2003-04-13 12:31:41 by CyberGuy
Maybe it'd be better to use RPN?
Posted on 2003-04-13 12:49:10 by Tomasz Grysztar
Uhm....whats RPN?
Posted on 2003-04-13 12:55:50 by CyberGuy
Ok now I've gotten the variables thing working.

macro calc
{
common
local ..flag
flag equ ..flag
flag = 0
forward
if num eqtype ""
if num = "+"
flag = 1
else if num = "-"
flag = 2
else if num = "*"
flag = 3
else if num = "/"
flag = 4
end if
else
if flag = 0
mov eax,num
else if flag = 1
add eax,num
else if flag = 2
sub eax,num
else if flag = 3
mov ebx,num
mul ebx
else if flag = 4
xor edx,edx
mov ecx,num
div ecx
end if
end if
}

calc ,"+",

I just need to order it correctly...
Posted on 2003-04-13 13:40:30 by CyberGuy