Here is my macros(Note they are made mostly for DWORD bytes):

***

;MOVML copies memory
MOVML MACRO Dest, Sour
PUSH Sour
POP Dest
ENDM

;ADDML adds Sour to Dest
ADDML MACRO Dest, Sour
MOV EAX, Sour
ADD Dest, EAX
ENDM

;SUBML subtracts Sour to Dest
SUBML MACRO Dest, Sour
MOV EAX, Sour
SUB Dest, EAX
ENDM

;MULML Multiplies Sour with Dest and saves the results in Dest
MULML MACRO Dest, Sour
MOV EAX, Sour
MUL Dest
MOVML Dest, EDX:EAX
ENDM

;DIVML divides Sour with Dest and saves the results in Dest
DIVML MACRO Dest, Sour
MOV EAX, Sour
DIV Dest
MOVML Dest, EDX:EAX
ENDM

***

When I use them something seems to go wrong with MOVML. Why is that?:confused:
Is there any mistakes in the other macros as well?:confused:


Julian

You help will always be appreciated by me.
Posted on 2003-09-20 06:57:55 by JulianS

Here is my macros(Note they are made mostly for DWORD bytes):

***

;MOVML copies memory
MOVML MACRO Dest, Sour
PUSH Sour
POP Dest
ENDM

;ADDML adds Sour to Dest
ADDML MACRO Dest, Sour
MOV EAX, Sour
ADD Dest, EAX
ENDM

;SUBML subtracts Sour to Dest
SUBML MACRO Dest, Sour
MOV EAX, Sour
SUB Dest, EAX
ENDM

;MULML Multiplies Sour with Dest and saves the results in Dest
MULML MACRO Dest, Sour
MOV EAX, Sour
MUL Dest
MOVML Dest, EDX:EAX
ENDM

;DIVML divides Sour with Dest and saves the results in Dest
DIVML MACRO Dest, Sour
MOV EAX, Sour
DIV Dest
MOVML Dest, EDX:EAX
ENDM

***

When I use them something seems to go wrong with MOVML. Why is that?:confused:
Is there any mistakes in the other macros as well?:confused:


Julian

You help will always be appreciated by me.



Fails every macro?
Posted on 2003-09-20 09:52:52 by onkelborg
It should not fail from my experience.



MOVmd MACRO Var1, Var2
push Var2
pop Var1
ENDM


Works fine for me.
Posted on 2003-09-20 10:48:22 by roticv
MOVML Dest, EDX:EAX
According to your MOVML macro, this would be translated into a
push EDX:EAX
I don't know which assembler you are using to accept that instruction nor how it would code it. MASM would most probably simply issue some error message when trying to assemble such an instruction.

Raymond
Posted on 2003-09-20 13:03:21 by Raymond

MOVML Dest, EDX:EAX

This is incorrect. EDX:EAX does NOT address the 64 bits contained in those two registers. The opcode docs write that way to indicate that EDX holds the high dword, but it is not correct assembler syntax. Besides, even if it was, how many bits does Dest have?

;DIVML divides Sour with Dest and saves the results in Dest
DIVML MACRO Dest, Sour
MOV EAX, Sour
DIV Dest
MOVML Dest, EDX:EAX
ENDM

DIV takes the number stored in EDX and EAX (EDX is the high DWORD) and divides it by the register you provide (when dealing with 16 or 8 bits the registers are DX:AX and AH:AL).
So for this to work properly you should clear EDX first, or you will get unexpected results.
The rest works just fine, so you just have to make this little corrections. :)
Th MOVML macro should work fine... what error code does MASM give you? Perhaps the error is in the part of your code that calls the macro, not in the macro itself :confused:
Posted on 2003-09-20 13:07:43 by QvasiModo
onkelborg - Every macro fails cause of MOVML except "ADDML" and "SUBML".

roticv - You told me how to copy data for my ML(Math language) so I guess it does not work for any byte type.

Raymond - is using "push EDX:EAX" really nessecary?

QvasiModo - The byte type should always be DWORD. Anyway when I use it I use DWORDs only and I get this
errror:

***

memory operand not allowed in context.

***


This is how I use it(of course this is just a example of some of the code changed so that you understand):


***

MyProc Proc A:DWORD, B:DWORD

MULML A, B;Here is the error
MOV EAX, A;This is just a part of the example
RET;So is this

MyProc ENDP

***

I would appreciate it if somebody took these macros and corrected the errors and told me what was wrong.
Please if you are to do so then try optimizing them for use with DWORD(Cause I am only gonna use DWORDS).
Whowever wants to end this thread and to help me really good, better do that. Thank you.
:grin:
Julian.
Posted on 2003-09-20 15:35:46 by JulianS
;MULML Multiplies Sour with Dest and saves the results in Dest
MULML MACRO Dest,Sour
xor edx,edx
mov ecx,Dest
MOV EAX, Sour
MUL ecx
MOVML Dest,EAX
ENDM
Posted on 2003-09-20 18:13:01 by devilsclaw
Raymond - is using "push EDX:EAX" really nessecary?
I never suggested that was necessary. I only pointed out that your own macro would generate such an instruction which, in my opinion, cannot be assembled properly.

A mul instruction with two 32-bit operands can produce a 64-bit result if the two operands are large enough. Without any prior knowledge of that possibility, you cannot use your macros to store the result blindly in a 32-bit area. If, however, you are absolutely certain that the result will never exceed 32 bits, then you could use the following macro (based on MASM syntax, other assemblers possibly requiring some modifications):
;MULML Multiplies Sour with Dest and saves the results in Dest

MULML MACRO Dest, Sour
MOV EAX, Sour
MUL Dest
MOVML Dest, EAX
ENDM
The above is also based on the assumption that if either (or both) parameter is a memory variable, it would have been declared as a DWORD. It also performs only unsigned multiplications.

Your division macro should be as follows, remembering that neither the EAX nor the EDX registers can be used as the destination (although either one could be used as the source):
;DIVML divides Sour with Dest and saves the results in Dest

DIVML MACRO Dest, Sour
MOV EAX, Sour
XOR EDX,EDX
DIV Dest
MOVML Dest, EAX
ENDM

devilsclaw:

There is NO need to rezero EDX before a multiplication. That register simply gets overwritten with the HIWORD of the 64-bit result. For example, the following instruction to multiply the content of EAX by the content of EDX is perfectly legitimate:
[b]mul edx[/b]
Raymond
Posted on 2003-09-20 19:15:55 by Raymond
i know there is no need... i still do it... i guess im just stuborn :)... sorry again..
Posted on 2003-09-20 19:25:03 by devilsclaw
MULML MACRO Dest, Sour
MOV EAX, Sour
MUL DWORD PTR Dest
MOVML DWORD PTR Dest, EAX
MOVML DWORD PTR Dest + 4, EDX
ENDM


U32 DWORD 123
U64 QWORD 123456

MULML U64, U32
Posted on 2003-09-20 20:15:09 by bitRAKE
All hail, here comes the king of marcos :grin:

Hey Julian,

I have been trying to tell you that there is no such thing as mov A, EDX:EAX or push EDX:EAX and so on. Basically you cannot use it as EDX:EAX. Bitrake is correct with the conversion, but that is only if the destination is a 8byte thing. However if the destination is 4bytes, then there is problem because the 64bit cannot be stored into one 32bit register. The only way around it is to store the hidword or lowdword.
Posted on 2003-09-20 21:58:31 by roticv
So the solution might be:
***

;MOVML copies memory
MOVML MACRO Dest, Sour
PUSH Sour
POP Dest
ENDM

;MULML Multiplies Sour with Dest and saves the results in Dest
MULML MACRO Dest, Sour
MOV ECX, Dest
MOV EAX, Sour
MUL ECX
MOVML Dest, EAX
ENDM

;DIVML divides Sour with Dest and saves the results in Dest
DIVML MACRO Dest, Sour
MOV ECX, Dest
MOV EAX, Sour
DIV ECX
MOVML Dest, EAX
ENDM

;ADDML adds Sour to Dest
ADDML MACRO Dest, Sour
MOV EAX, Sour
ADD Dest, EAX
ENDM

;SUBML subtracts Sour to Dest
SUBML MACRO Dest, Sour
MOV EAX, Sour
SUB Dest, EAX
ENDM

***

Okay, "SUBML" and "ADDML" seems to work good, so I did not make anything to them.
Then I took devilsclaw version without "XOR" and made a "DIVML" and a "MULML".
When I tested it, it worked perfect. So I guess you just have to store the values in registers and then it would work. maybe even faster, cause of the registers.

Anyway there is a new version of ML(Math Language) in the ML thread.

###
May math only leave the foolish. So I guess I'm not foolish any more.
###

Thanks alot.

Julian
Posted on 2003-09-21 04:44:20 by JulianS
Then I took devilsclaw version without "XOR" and made a "DIVML" and a "MULML".
devilsclaw's example was only for your MULML macro and it would obviously work without the "XOR" (see my former reply on that).

However, you must understand that the DIV instruction divides the 64-bit value of EDX:EAX when the divisor is a 32-bit source. If the value which must be divided is small enough to fit entirely into the EAX register, it is IMPERATIVE that the EDX register be clear before the division operation. Otherwise, the result will be wrong, AND you even risk crashing your program if the value remaining in the EDX register is larger than or equal to the divisor.
May math only leave the foolish. So I guess I'm not foolish any more
Raymond
Posted on 2003-09-21 08:43:53 by Raymond
how can i make MACRO for this:

setcur proc near
mov ah,02
mov bh,00
mov dh,row
mov dl,col
int 10h
Posted on 2003-09-21 11:09:38 by ampdeck


setcur marco row, col
mov ah,02
mov bh,00
mov dh,row
mov dl,col
int 10h
endm
Posted on 2003-09-21 11:28:12 by roticv
So the DIVML macro should be:

***

;DIVML divides Sour with Dest and saves the results in Dest
DIVML MACRO Dest, Sour
MOV ECX, Dest
MOV DX, Sour
MOV AX, Sour
DIV ECX
MOVML Dest, AX
ENDM

***

Well, I gotta say I tested it(Only compiled and nothing seemed wrong. However I never really tested the exe out.). Anyway thanks Raymond. If you noticed anything else wrong then let me know.


###
I guess it just needed alittle more time before it came back to me:)
###

Julian
Posted on 2003-09-21 15:01:32 by JulianS
DIVML MACRO Dest, Sour
MOV ECX, Dest
xor edx,edx
MOV EAX, Sour
DIV ECX
MOVML Dest, AX
ENDM


it actually depends in this case how you want to divide Dest might need to be in EAX and Sour in ECX you might want to make sure
Posted on 2003-09-21 16:23:35 by devilsclaw


DIVML MACRO Dest, Sour
MOV ECX, Dest
MOV EAX, Sour
CDQ
DIV ECX
MOV Dest,EAX
ENDM

Could this be better?
Posted on 2003-09-22 13:26:34 by QvasiModo
QvasiModo i do know Clearing EDX for DIV also if IDIV is in single operand mod, to be good practice since DIV can crash sometimes if you dont. Unless the converting it to a QWORD solves that problem..
Posted on 2003-09-22 13:31:04 by devilsclaw
Both our macros clear EDX. The instruction CDQ is one byte shorter than XOR EDX,EDX. Howeer I just realized this is not a good idea for an unsigned math macro, since CDQ copies the sign bit of EAX to EDX... :P
Posted on 2003-09-22 14:03:44 by QvasiModo