Re: Binary conversion (machine)
Don <Graebel at hotmail.com> wrote:
>> 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.
Well, it was the decision of ASM.EX to do so.
The main difference is, that ASM.EX provided a different opcode for
mov eax, [mem]
----------------------------------------------------------------------
-- Here's again your program, with (concerning the asm code) only this
-- one byte changed, and it works!
include machine.e
atom mem, SwapBytes
sequence Code_Space
mem = allocate( 4 )
poke4( mem, #12345678 )
Code_Space =
{
#50, -- push eax
-- #B8} & int_to_bytes(mem) & -- mov eax, offset mem * old
#A1} & int_to_bytes(mem) & -- mov eax, offset mem * new
{ #0F, #C8, -- bswap eax
#A3} & int_to_bytes(mem) & -- mov offset mem, eax
{ #58, -- pop eax
#C3 -- ret
}
SwapBytes = allocate( length(Code_Space) )
poke( SwapBytes, Code_Space )
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 )
----------------------------------------------------------------------
> 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.
It did almost all the coding automatically. I think it will be worth
looking at it. AFAIK the version at
http://www.harborside.com/~xseal/euphoria/download.html
is newer than the version in the RDS archive.
> 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.
Ah, thats a good idea to get unknown opcodes.
> Put the rest of it together myself. Got the idea from
> euphoria/dos/demo/callmach.ex.
> Don
Regards,
Juergen
|
Not Categorized, Please Help
|
|