Machine Code macros 
Author Message
 Machine Code macros

Hi,

I need a few simple machine code macro for functions like plus, minus,
multiply and divide that take one parameter and use the accumulator or a
register for the other parameter and store the result in the accumulator or
a register.  Where could I go to find some help with this?

Thanks,
Darren



Sat, 02 Nov 2002 03:00:00 GMT  
 Machine Code macros

Quote:

>I need a few simple machine code macro for functions like plus, minus,
>multiply and divide that take one parameter and use the accumulator or a
>register for the other parameter and store the result in the accumulator or
>a register.  Where could I go to find some help with this?

You need to tell us what sort of machine code you want
(32-bit x86, 16-bit x86, MIPS, 6502, Alpha, Z80 or whatever)
You also need to tell us what macro processor it's for.

S.



Sat, 02 Nov 2002 03:00:00 GMT  
 Machine Code macros
Hi,

I should have mentioned that.  It's just 32-bit x86.

I don't really want a macro to compile in an assembler. What I really want
is an example of how to code plus, minus, divide and multiply.  I think it
needs to use relative addressing.

Each piece of machine code should be able to put together in a heirarchical
structure.  At the bottom of the structure would be the data and the next
level up should be the instructions.  The very top of the heirachy would be
the result.

Like this:

1
    +
2
        *    =  15
5

The result of 1+2 is a parameter for the * function.  Then the * function
multiplies 3 * 5 and leaves the answer on the stack or in the accumulator.
The = isn't in the program, it's only there to better show what the code is
doing.

I want to be able to put the functions together like Legos.  I can write the
program to put them together.  I just need a kick start to get it going
because I haven't done any ASM programming.   I have only hand-coded machine
language for the 6510.

How do you think I should approach this?

Thanks very much,
Darren


Quote:

> >I need a few simple machine code macro for functions like plus, minus,
> >multiply and divide that take one parameter and use the accumulator or a
> >register for the other parameter and store the result in the accumulator
or
> >a register.  Where could I go to find some help with this?

> You need to tell us what sort of machine code you want
> (32-bit x86, 16-bit x86, MIPS, 6502, Alpha, Z80 or whatever)
> You also need to tell us what macro processor it's for.

> S.



Sat, 02 Nov 2002 03:00:00 GMT  
 Machine Code macros

Quote:

>How do you think I should approach this?

If I've understand you correctly, the following is what you need:

    Operation                 Encoding

    EAX = EAX + NUM           05 <NUM>
    EAX = EAX - NUM           2D <NUM>
    EAX = NUM - EAX           2D <NUM> F7 D8
    EAX = EAX * NUM           69 C0 <NUM>
    EAX = EAX / NUM           31 D2 B9 <NUM> F7 F1
    EAX = NUM / EAX           31 D2 89 C1 B8 <NUM> F7 F1

Here EAX is the accumulator, and NUM is a 32-bit integer that you
supply.  <NUM> represents the (little-endian) byte-encoding of NUM.

Addition, subtraction and multiplication are modulo 2^32.
Division rounds towards 0.  I've assumed your numbers are unsigned -
if they are signed then the division encoding would be different.
The divison operations use EDX and ECX as scratch registers.

S.



Sat, 02 Nov 2002 03:00:00 GMT  
 Machine Code macros
Yes! Thank you very much!

If I have a 32 bit integer and I place it in the machine code, I put the
least significant 16 bits first. Or do I have it backwords?

I will be doing a floating point version of these instruction but I will use
integers first.

Thanks,
Darren


Quote:

> >How do you think I should approach this?

> If I've understand you correctly, the following is what you need:

>     Operation                 Encoding

>     EAX = EAX + NUM           05 <NUM>
>     EAX = EAX - NUM           2D <NUM>
>     EAX = NUM - EAX           2D <NUM> F7 D8
>     EAX = EAX * NUM           69 C0 <NUM>
>     EAX = EAX / NUM           31 D2 B9 <NUM> F7 F1
>     EAX = NUM / EAX           31 D2 89 C1 B8 <NUM> F7 F1

> Here EAX is the accumulator, and NUM is a 32-bit integer that you
> supply.  <NUM> represents the (little-endian) byte-encoding of NUM.

> Addition, subtraction and multiplication are modulo 2^32.
> Division rounds towards 0.  I've assumed your numbers are unsigned -
> if they are signed then the division encoding would be different.
> The divison operations use EDX and ECX as scratch registers.

> S.



Sat, 02 Nov 2002 03:00:00 GMT  
 Machine Code macros

Quote:

>If I have a 32 bit integer and I place it in the machine code, I put the
>least significant 16 bits first. Or do I have it backwords?

An example: the number 305419896 (12345678 hex) would be written as
the four bytes:

    78 56 34 12

S.



Sat, 02 Nov 2002 03:00:00 GMT  
 Machine Code macros
Excellent! Thanks again.


Quote:

> >If I have a 32 bit integer and I place it in the machine code, I put the
> >least significant 16 bits first. Or do I have it backwords?

> An example: the number 305419896 (12345678 hex) would be written as
> the four bytes:

>     78 56 34 12

> S.



Sat, 02 Nov 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Lisp Based Machine Code (Simulators) [was Re: Lisp Machines]

2. Lisp Based Machine Code (Simulators) [was Re: Lisp Machines]

3. A macro involving two sub-macros - where the 2nd macro needs results from the first

4. Help needed with Macro coding

5. Timeused macro - got sample code ?

6. getting undefined op-code with macros

7. Clipper Macros and Code Blocks

8. can i see the macro code in labview?

9. Creating large code blocks using macros

10. Macro Operator and Code Blocks

11. macros in code

12. expanding macros in my assembly code

 

 
Powered by phpBB® Forum Software