RE: Binary conversion (machine)

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

> The following code works for me:
> 
> --------------------------------------------------------
> include machine.e
> 
> atom mem
> mem = allocate(4)
> 
> constant SwapBytes = allocate(15)
> poke(SwapBytes, {
>     #50,                    --    0: push eax
>     #A1,#00,#00,#00,#00,    --    1: mov eax, [mem] (2)
>     #0F, #C8,               --    6: bswap eax
>     #A3,#00,#00,#00,#00,    --    8: mov [mem], eax (9)
>     #58,                    --    D: pop eax
>     #C3})                   --    F: ret
> poke4(SwapBytes + 2, mem)
> poke4(SwapBytes + 9, mem)
> 
> poke4(mem, #90)
> -- poke4(mem, #12345678)  -- better for demonstration
> 
> printf(1, "%08x\n", peek4u(mem))
> call( SwapBytes )
> printf(1, "%08x\n", peek4u(mem))
> call( SwapBytes )
> printf(1, "%08x\n", peek4u(mem))
> call( SwapBytes )
> printf(1, "%08x\n", peek4u(mem))
> 
> free(SwapBytes)
> free(mem)
> --------------------------------------------------------
> 
> 
> When I first tried to compile the asm code with Pete
> Eberlein's ASM, I got the following error message:
> 
>   ---------------------------------
>   ASM to Euphoria compiler (32-bit)
>   by Pete Eberlein    Dec 29, 2001
>   ---------------------------------
>   Line 4: Not a valid instruction 'bswap'
> 
> Mmmm, must be "Line 3" ...
> 
> Anyway, I had to compile the asm code without the "bswap"
> instruction, and insert the opcode manually.
> Don, how did you get the opcode for "bswap eax"? Is there
> a newer version of ASM.EX?
> 
> Regards,
>    Juergen

Ahh, hmm.  Same routine but poke4'd the memory location in
directly.  I am going to have to experiment with this a little
more when I have some time.

And to answer your question, I have no idea about ASM.EX =)I didnt even 
know it existed.  I have two assembly compilers here I have been making 
programs in.  Well all I did was create a basic window and bswap'd eax 
and sent it through a decompiler to see what codes it was using.  Put 
the rest of it together myself.  Got the idea from 
euphoria/dos/demo/callmach.ex.

Don

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

Search



Quick Links

User menu

Not signed in.

Misc Menu