Re: ASM.E question for PETE

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi Bernie,

On Fri, 10 Dec 1999 13:17:30 -0500, Bernie Ryan <bwryan at PCOM.NET> wrote:
>Pete:
>
>   Will you please explain to me how you add instructions to the asm.e
>file using the sample entry below. I understand the #F6 is the first opcode
>I know that #F6D0 would mean NOT al register. I do not understand how
>the #D0 part is generated by the #10 + MODRM
>
>    {"NOT",     {#F6, #10 + MODRM}},

The "NOT" is the name of the opcode, followed by one or more sequences of
byte encodings.

The #F6 is a literal byte.
The #10 is part of the MOD/RM field in the instruction.  The MODRM is a
modifier that the asm parser knows to replaces with a Register or Memory
encoding.
The lower 3 bits are for the Register index (AL = 000, in this case)
The upper 2 bits determine whether its a register or memory. (11 for
register)

The remaining 3 bits in the middle can be used to tell between other
instructions that start with #F6.  So the only hex values that we can have
there are #00, #08, #10, #18, #20, #28, #30, #38.

So we have
      bits        hex
      --------    ---
      11___000  = #C0 (from MODRM)
 +    00010000  = #10
                = #D0


... In retrospect, doing it that way was really dumb.  Using modifiers using
bits makes it really hard to understand and add new instructions.



>The instructions I want to add are the SETcc ( byte set on condition code )
>the eaxmples are:
>
>                                            opcode   instruction
>SETG AL  -- which should generate #0F9FC0 ( #0F9F     SETG r/8m )
>SETL AH  -- which should generate #0F9CC4 ( #0F9C     SETL r/8m )
>...... etc
>
>Thanks
>Bernie

Add these to asm.e:
    {"SETG",    {#0F, #9F, #00 + MODRM}},
    {"SETL",    {#0F, #9C, #00 + MODRM}},


---------------------------
-- SETcc.ex test program

include asm.e

asm_output(1, 1)

? get_asm(
"not al "&
"setg al "&
"setl ah ")


--------------
-- output:

constant proc = allocate(8)
poke(proc, {
    #F6,#D0,                --    0: not al
    #0F,#9F,#C0,            --    2: setg al
    #0F,#9C,#C4})           --    5: setl ah
134825648


This appears to do what you want.  I could probably add all the SETcc
instructions to asm.e pretty easily.  I finished my last final a half-hour
ago, so now I have more time to code in Euphoria.  I've started making a
LL(1) parser, so you can throw any grammar at it and have it parse a file or
something.  I made it so that each rule in the grammar will attempt to call
a function of the same name, so that it can do stuff with the parsed data.
It should be suitable for writing a new asm parser, I hope.

--Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu