Hi, new version. Uses MOVS to convert now, cause I found it better then the old one.
It now includes error support. And I've removed that old error you spotted Victor.
It uses macros depending on the math.(Just like you said:grin:)
Note that there is only macros for Addition and Subtraction.
Should I make it for Division and Multiplying?
Suggestions very much appreciated.

Julian
Posted on 2003-09-17 12:45:35 by JulianS
Here is the exe.
Posted on 2003-09-17 12:46:16 by JulianS
Hey Julian,

Did you really read through my comments? There are somethings that I have mentioned that are still not changed. Also you really should try compiling the generated output to get an idea of what is wrong.
Posted on 2003-09-18 02:23:04 by roticv
Look, I've read it all but I want to try it out to see if it is working good.

About testing:

I will release a new version tommorow or the day after and then I've tested the code but I may still post a question like:

***

Why does that opcode error happen when I use....

***

Just to let you know.

Anyway before I begin making macros for everything, I need to know is there a better/quicker/alike methode that I may want to use?

Also:
I plan making Macros for something like: Cos, Sin, Sgn and Abs....

I please tell me any suggestions conserning the macro function/methode.

Any ideas wanted.

Julian
Posted on 2003-09-18 07:41:29 by JulianS
Sorry for my harsh words, was tired. For Cos and Sin you need to make use of fpu. So you need to learn that if you want to add functionalities to them. (Not too sure about abs though). I got a cool snipplet for you for sgn:


sng(x) ; returns sign in -1, 0 or 1
;eax = input
;edx = output
cdq
cmp edx,eax
adc edx,0

I have no idea about any faster way.
Posted on 2003-09-18 07:47:58 by roticv
Okay. But what shall I use macros for? "+" "*" "-" "/" "Cos" "Sin"?
And one more thing? How do I use a macro when I have made one?
Please be accurate.

Julian
Posted on 2003-09-18 07:53:19 by JulianS
Marcos are just aids to help you code lesser. However for me I do not really use them much, except for once in a while.

Let me make a suggestion to you

For code like


A = sgn(B)

You can try generating code like


mov eax, A
cdq
cmp edx, eax
adc edx, 0
mov B, edx

Like I did mention eariler that cos and sin needs fpu, so the return value would be on the fpu stack. Personally I do not like mixing fpu codes with normal "integer" codes. Just my personal opinions.
Posted on 2003-09-18 08:23:40 by roticv
So you think I shall make as many macros as nessecary?
I mean I could, I could even do like in my old release where the macros is only added if the there is use for them.

Is that a good idea? Or shall I just make it so they are added no matter what? Or just a function that you can put on and they are added no matter what?

:confused:


Could you also give me macros to multiply and to divide?


Thanks alot.
Posted on 2003-09-18 11:32:40 by JulianS
No need for any macros anymore. I've made them myself.

Features:

###

Variable creation for: 1, 2, 4, 6, 8, 10 bytes.
Math support for: Addition, Subtracting, Multiplying & Division.
Support for error submiting(If an error appears then It will save the data to the clipboard and suggest that you post the data in this forum).
Refference Included.

###

Is there any place I should put this program so that people would notice it without getting the source code(Private;)), anyway it is gonna be freeware.

Though the program may still have some mistakes, even though I tested it and found none.

Help is as aways appreciated.

Thanks alot for helping me (specially to you Victor;))


Julian
Posted on 2003-09-18 13:13:24 by JulianS
No need for any macros anymore. I've made them myself.

Features:

###

Variable creation for: 1, 2 , 4, 6, 8, 10 bytes..
Math support for: Addition, Subtracting, Multiplying & Division.
Support for error submiting(If an error appears then It will save the data to the clipboard and suggest that you post the data in this forum).
Refference Included.

###

If there is any place I should put this program so that people would notice it without getting the source code(Private;)), anyway it is gonna be freeware.

Though the program may still have some mistakes, even though I tested it and found none.

Help is as aways appreciated.

Thanks alot for helping me (specially to you Victor;))


Julian
Posted on 2003-09-18 13:15:40 by JulianS


A as (10)bytes
B as (10)bytes

A = A + B

Generates


MOVML MACRO Dest, Sour
PUSH Sour
POP Dest
ENDM
ADDML MACRO Dest, Sour
MOV EAX, Sour
ADD Dest, EAX
ENDM


LOCAL A :TBYTE
LOCAL B :TBYTE

ADDML B, A
MOVML A, B

A and B cannot fit into eax. eax is a 32bit register while A and B are 80bit.


A = A * B

Generates:


MOVML MACRO Dest, Sour
PUSH Sour
POP Dest
ENDM
MULML MACRO Dest, Sour
MOV EAX, Sour
IDIV Dest
MOVML Dest, EDX:EAX
ENDM


MULML B, A
MOVML A, B

idiv is signed division. You should be using either imul or mul instead. Looking at somemore generated code I realised that you have mixed up division and multiplication. imul/mul is for multiplication and div/idiv is for division. Also when doing divison remember to either do cdq or xor edx, edx, since division makes use of both eax and edx.
Posted on 2003-09-19 00:08:23 by roticv
You mentioned that the macros where wrong.
I mean that's cause of the byte size, right?
Then how would you do it? Maybe using ".If" or somehow just manage the byte sizes?
Please show me how the macros should be made for: ADDML, SUBML, MULML, DIVML and MOVML(Only if it is not correct made already).

Thank you.;)

Julian
Posted on 2003-09-19 06:52:25 by JulianS
Generally in my life of programming (which was pretty short), I did not really mix data of different size. Let me give you a scenario, You have 2 variables, A and B. A is 4bytes while B is 2 bytes. B = B + A is stupid because the upper values of A would be lost. However of course A = B + A makes more sense.

Also I see no point in mixing different data type. For example making using of 16bit register/memory takes up one more byte (for the prefix 66h). You are just making your life hard for yourselves. Regarding data type bigger than 32bit, so far I have yet to see anyone use FWORD. QWORD could be used for mmx, and fpu, but other than that I think it would be difficult to use. TBYTE is definitely used for fpu (eg REAL10). hmm what's the data type for xmm? I can't really recall...
Posted on 2003-09-19 07:22:47 by roticv
Hi, I have corrected that error you've spotted Victor about the macros:)

So you are actually think I should remove the other data types? I mean only allow DWORD?
Anyway you never answered my question about how to make the macros.
I still belive that there migth be some mistakes in the macros. Here they are:

***

MOVML MACRO Dest, Sour
PUSH Sour
POP Dest
ENDM

ADDML MACRO Dest, Sour
MOV EAX, Sour
ADD Dest, EAX
ENDM

SUBML MACRO Dest, Sour
MOV EAX, Sour
SUB Dest, EAX
ENDM

MULML MACRO Dest, Sour
MOV EAX, Sour
IMUL Dest"
MOVML Dest, EDX:EAX
ENDM

DIVML MACRO Dest, Sour
MOV EAX, Sour
IDIV Dest"
MOVML Dest, EDX:EAX
ENDM

***

Are they okay or what?
And can you tell me where I can upload the program but not the source?

Maybe people will use my program for a macro tutorial instead of using it to do easy math. just kidding:grin:


I REALLY want some suggetions to ML.

Julian
Posted on 2003-09-19 07:46:57 by JulianS
Hi, I have corrected that error you've spotted Victor about the macros:)

So you are actually think I should remove the other data types? I mean only allow DWORD?
Anyway you never answered my question about how to make the macros.
I still belive that there migth be some mistakes in the macros. Here they are:

***

MOVML MACRO Dest, Sour
PUSH Sour
POP Dest
ENDM

ADDML MACRO Dest, Sour
MOV EAX, Sour
ADD Dest, EAX
ENDM

SUBML MACRO Dest, Sour
MOV EAX, Sour
SUB Dest, EAX
ENDM

MULML MACRO Dest, Sour
MOV EAX, Sour
IMUL Dest"
MOVML Dest, EDX:EAX
ENDM

DIVML MACRO Dest, Sour
MOV EAX, Sour
IDIV Dest"
MOVML Dest, EDX:EAX
ENDM

***

Are they okay or what?
And can you tell me where I can upload the program but not the source?

Maybe people will use my program for a macro tutorial instead of using it to do easy math. just kidding:grin:


I REALLY want some suggetions to ML.

Julian
Posted on 2003-09-19 07:57:21 by JulianS
Hi, Look I've tried to make a function that tests if a point is within a triangle. Some of you may know about this.
Anyway here the code I used(Complete):

***

; #########################################################################
;
; Build this DLL from the batch file called BldDLL.bat
;
; #########################################################################

.386
.model flat, stdcall
option casemap :none ; case sensitive

; #########################################################################

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

; #########################################################################

szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM

m2m MACRO M1, M2
push M2
pop M1
ENDM

return MACRO arg
mov eax, arg
ret
ENDM

.data

;Defines the Pos2D Structure. The Pos2D Structure holdes a X and an Y Position, that makes a 2D cordinate
Pos2D STRUCT
XPos DWORD ?
YPos DWORD ?
Pos2D ENDS

;Defines the Pos3D Structure. The Pos3D Structure holdes a X, Y and a Z Position, that makes a 3D cordinate
Pos3D STRUCT
XPos DWORD ?
YPos DWORD ?
ZPos DWORD ?
Pos3D ENDS

;Defines the Triangle Structure. The Triangle Structure holdes 3 3D cordinates: FirstPosition, SecondPosition and ThirdPosition. The 3 3D Cordinates makes up a triangle
Triangle STRUCT
FirstPosition Pos3D <>
SecondPosition Pos3D <>
ThirdPosition Pos3D <>
Triangle ENDS

;Defines the Camera Structure. The Camera Structure holdes 3D Cordinates and angles: AngleRightLeft and AngleUpDown. The 3D Cordinates makes up the camera position and the angles makes up the viewpoint
Camera STRUCT
Position Pos3D <>
AngleRightLeft DWORD <>
AngleUpDown DWORD <>
Camera ENDS

.data?
p2d Pos2D <?>

.code



MOVML MACRO Dest, Sour
PUSH Sour
POP Dest
ENDM

ADDML MACRO Dest, Sour
MOV EAX, Sour
ADD Dest, EAX
ENDM

SUBML MACRO Dest, Sour
MOV EAX, Sour
SUB Dest, EAX
ENDM

MULML MACRO Dest, Sour
MOV EAX, Sour
IMUL Dest
MOVML Dest, EDX:EAX
ENDM

; ##########################################################################

LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD

szText LmTitle,"tstdll's LibMain Function"

.if reason == DLL_PROCESS_ATTACH
; szText ATTACHPROCESS,"PROCESS_ATTACH"
; invoke MessageBox,NULL,ADDR ATTACHPROCESS,addr LmTitle,MB_OK

return TRUE
; -----------------------------
; If error at startup, return 0
; System will abort loading DLL
; -----------------------------

.elseif reason == DLL_PROCESS_DETACH
; szText DETACHPROCESS,"PROCESS_DETACH"
; invoke MessageBox,NULL,addr DETACHPROCESS,addr LmTitle,MB_OK

.elseif reason == DLL_THREAD_ATTACH
; szText ATTACHTHREAD,"THREAD_ATTACH"
; invoke MessageBox,NULL,addr ATTACHTHREAD,addr LmTitle,MB_OK

.elseif reason == DLL_THREAD_DETACH
; szText DETACHTHREAD,"THREAD_DETACH"
; invoke MessageBox,NULL,addr DETACHTHREAD,addr LmTitle,MB_OK

.endif

ret

LibMain Endp

; ##########################################################################

MakePos2D proc X:DWORD, Y:DWORD

mov eax,OFFSET p2d
mov edx,X
mov .Pos2D.XPos, edx
mov edx,Y
mov .Pos2D.YPos, edx

ret ; return the value in eax

MakePos2D endp

IsInTriangle proc PointX:DWORD, PointY:DWORD, TAX:DWORD, TAY:DWORD, TBX:DWORD, TBY:DWORD, TCX:DWORD, TCY:DWORD

LOCAL bc :DWORD
LOCAL ca :DWORD
LOCAL ab :DWORD
LOCAL ap :DWORD
LOCAL bpr :DWORD
LOCAL cp :DWORD
LOCAL abc :DWORD

MULML cy, bx
MOVML edx, cy

MULML cx, by
MOVML ebx, cx

SUBML ebx, edx
MOVML bc, ebx



MULML ay, cx
MOVML edx, ay

MULML ax, cy
MOVML ebx, ax

SUBML ebx, edx
MOVML ca, ebx



MULML by, ax
MOVML edx, by

MULML bx, ay
MOVML ebx, bx

SUBML ebx, edx
MOVML ab, ebx


MULML py, ax
MOVML edx, py

MULML px, ay
MOVML ebx, px

SUBML ebx, edx
MOVML ap, ebx


MULML py, bx
MOVML edx, py

MULML px, by
MOVML ebx, px

SUBML ebx, edx
MOVML bpr, ebx


MULML py, cx
MOVML edx, py

MULML px, cy
MOVML ebx, px

SUBML ebx, edx
MOVML cp, ebx


ADDML ca, bc
ADDML ab, ca
MOVML abc, ab

;sng(x) ; returns sign in -1, 0 or 1
;eax = input
;edx = output
CDQ
CMP eax, edx
ADC eax, 0

ret

IsInTriangle endp

TestProc proc bar:DWORD, ra:DWORD

mov eax, bar ; start with eax, since the function return is there

dec eax ; increment

mov ra, eax

dec ra

ret ; return the value in eax

ASSUME eax:nothing

TestProc endp

; ##########################################################################

End LibMain

***

The code contains an example of a proc and then the IsInTriangle proc.
The IsInTriangle proc is the hole reason why I did this.

If you try to compile you will get alot of errors. Most of the is saying: "Instruction operands must be the same size".
It also says that I make an invalid use of the register.
And it mentions some undefined symbols.
Is this my fault or ML's fault(It's my fault anyway).

What's wrong?
I really want to get this done, cause I still have another 10 procs to make.
And when they are made my 3D Engine is done and I will start making my first 3D Game.(Note that I already have the codes for the engine in VB but it is all to slow. That's where assembly comes in.)
Posted on 2003-09-19 10:09:02 by JulianS
You don't really have to answer the last thread(I've found the answer) nor this one.
The final version includes macros that has been tested and optimized perfectly.
It also features a new error handling system. That means that if there is an error the program will let you know and suggest that you email me athttp://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=6234bc812276459eb27b9c3de33dbccc.
:)
Thanks to everybody for helping me with this project and feel free to upload this zip file to an server or alike so that more people can use it.

Julian:grin:
Posted on 2003-09-21 05:10:26 by JulianS
I've attached a file containing an HLA macro that does this same thing as a macro inside HLA (i.e., you don't have to run a separate program to get the code). Here's the comments at the beginning of the file that explain the macro's use:



// u32expr.hla
//
// This program demonstrates how to write an "expression compiler"
// using the HLA compile-time language. This code defines a macro
// (u32expr) that accepts an arithmetic expression as a parameter.
// This macro compiles that expression into a sequence of HLA
// machine language instructions that will compute the result of
// that expression at run-time.
//
// The u32expr macro does have some severe limitations.
// First of all, it only support uns32 operands.
// Second, it only supports the following arithmetic
// operations:
//
// +, -, *, /, <, <=, >, >=, =, <>.
//
// The comparison operators produce zero (false) or
// one (true) depending upon the result of the (unsigned)
// comparison.
//
// The syntax for a call to u32expr is
//
// u32expr( register, expression )
//
// The macro computes the result of the expression and
// leaves this result sitting in the register specified
// as the first operand. This register overwrites the
// values in the EAX and EDX registers (though these
// two registers are fine as the destination for the
// result).
//
// This macro also returns the first (register) parameter
// as its "returns" value, so you may use u32expr anywhere
// a 32-bit register is legal, e.g.,
//
// if( u32expr( eax, (i*3-2) < j )) then
//
// << do something if (i*3-2) < j >>
//
// endif;
//
// The statement above computes true or false in EAX and the
// "if" statement processes this result accordingly.



Here's a short code sequence that does RPN to Asm translations:



// This program translates user RPN input into an
// equivalent sequence of assembly language instrs (HLA fmt).

program RPNtoASM;

#include( "stdlib.hhf" );

static

s: string;
operand: string;
StartOperand: dword;


#macro mark;

mov( esi, StartOperand );

#endmacro;

#macro delete;

mov( StartOperand, eax );
sub( eax, esi );
inc( esi );
sub( s, eax );
str.delete( s, eax, esi );

#endmacro;

procedure length( s:string ); returns( "eax" ); @nodisplay;
begin length;

push( ebx );
mov( s, ebx );
mov( (type str.strRec [ebx]).length, eax );
pop( ebx );

end length;


begin RPNtoASM;

stdout.put( "-- RPN to assembly --" nl );
forever

stdout.put( nl nl "Enter RPN sequence (empty line to quit): " );
stdin.a_gets();
mov( eax, s );
breakif( length( s ) = 0 );
while( length( s ) <> 0 ) do

pat.match( s );

// Match identifiers and numeric constants

mark;
pat.zeroOrMoreWS();
pat.oneOrMoreCset( {'a'..'z', 'A'..'Z', '0'..'9', '_'} );
pat.a_extract( operand );
stdout.put( " pushd( ", operand, " );" nl );
strfree( operand );
delete;

pat.alternate;

// Handle the "+" operator.

mark;
pat.zeroOrMoreWS();
pat.oneChar( '+' );
stdout.put
(
" pop( eax );" nl
" add( eax, [esp] );" nl
);
delete;

pat.alternate;

// Handle the '-' operator.

mark;
pat.zeroOrMoreWS();
pat.oneChar( '-' );
stdout.put
(
" pop( eax );" nl
" pop( ebx );" nl
" sub( eax, ebx );" nl
" push( ebx );" nl
);
delete;

pat.alternate;

// Handle the '*' operator.

mark;
pat.zeroOrMoreWS();
pat.oneChar( '*' );
stdout.put
(
" pop( eax );" nl
" imul( eax, [esp] );" nl
);
delete;

pat.alternate;

// handle the '/' operator.

mark;
pat.zeroOrMoreWS();
pat.oneChar( '/' );
stdout.put
(
" pop( ebx );" nl
" pop( eax );" nl
" cdq(); " nl
" idiv( ebx, edx:eax );" nl
" push( ebx );" nl
);
delete;

pat.if_failure

// If none of the above, it must be an error.

stdout.put( nl "Illegal RPN Expression" nl );
mov( s, ebx );
mov( 0, (type str.strRec [ebx]).length );

pat.endmatch;

endwhile;

endfor;

end RPNtoASM;


Cheers,
Randy Hyde
Posted on 2003-09-22 12:06:24 by rhyde