flat assembler
Message board for the users of flat assembler.
Index
> Non-x86 architectures > [ARM] X86 Conversion: LEA R,[S*I+B+D], SETCC, XCHG, etc |
Author |
|
m3ntal 15 Jul 2014, 20:58
Another attempt to convert X86 instructions to ARM. Example:
Code: lea r1, [r2] lea r1, [r2+r3] lea r1, [r2+10000000h] lea r1, [r2-20000000h] lea r1, [r2*3] lea r1, [r2*4] lea r1, [r2*5] lea r1, [r2*10] lea r1, [r2+r3*4] lea r1, [r4+r7*2+30000000h] lea r2, 40000000h lea r3, [50000000h] lea r4, [60000000h+r7] lea r5, [70000000h+r7*8] Code: 00000000 E1A01002 mov r1, r2 00000004 E0821003 add r1, r2, r3 00000008 E2821201 add r1, r2, 10000000h 0000000C E2421202 sub r1, r2, 20000000h 00000010 E0821082 add r1, r2, r2, lsl 1 00000014 E1A01102 mov r1, r2, lsl 2 00000018 E0821102 add r1, r2, r2, lsl 2 0000001C E0821102 add r1, r2, r2, lsl 2 00000020 E0811001 add r1, r1, r1 00000024 E0821103 add r1, r2, r3, lsl 2 00000028 E0841087 add r1, r4, r7, lsl 1 0000002C E2811203 add r1, r1, 30000000h 00000030 E3A02101 mov r2, 40000000h 00000034 E3A03205 mov r3, 50000000h 00000038 E2874206 add r4, r7, 60000000h 0000003C E3A05207 mov r5, 70000000h 00000040 E0855187 add r5, r5, r7, lsl 3 Code: macro lea [p] { common define ?s 0 match r=,[x], p \{ ; r,[?] if x is.r32? ; r,[r] mov r, x else ; r,[?] match =0 \ a+b*c, ?s x \\{ match n+i, c \\\{ ; a+b*c+i addms r, a, b, n if use.ror? add r, i else ldr r12, =i add r, a, r12 end if define ?s 1 \\\} if ?s eq 0 if a is.r32? \ ; r+r*c & b is.r32? addms r, a, b, c else if b is.r32? \ ; i+r*c & a is.i? if use.ror.a? mov r, a addms r, r, b, c else ldr r12, =i add r, a, r12 end if else 'Error' end if end if define ?s 1 \\} match =0 \ a+b, ?s x \\{ if a is.r32? \ ; r+i & b is.i? if use.ror.b? add r, a, b else ldr r, =b add r, a, r end if else if \ b is.r32? & \ ; i+r a is.i? if use.ror.a? add r, b, a else ldr r, =a add r, b, r end if else ; assume add r, a, b ; r=a+b end if define ?s 1 \\} match =0 \ a-b, ?s x \\{ ; r-i if a is.r32? \ & b is.i? if use.ror.b? sub r, a, b else ldr r, =b sub r, a, r end if else ; ?,? 'Error' end if define ?s 1 \\} match =0 \ a*b, ?s x \\{ ; r=a*n if b eq 4 mov r, a, lsl 2 ; r=a*4 else if b eq 2 mov r, a, lsl 1 ; r=a*2 else if b eq 3 add r, a, a, lsl 1 ; r=a*3 else if b eq 5 add r, a, a, lsl 2 ; r=a*5 else if b eq 10 add r, a, a, lsl 2 ; r=a*10 add r, r else ; *? 'Error' end if define ?s 1 \\} if ?s eq 0 ; r=[i] ldr r, =x end if end if define ?s 1 \} match =0 \ ; no [] a=,b, ?s p \{ if a is.r32? ; r,? if b is.r32? ; r,r mov a, b else if b is.i? ; r,i ldr a, =b else ; r,? 'Error' end if else ; ?,? 'Error' end if define ?s 1 \} if ?s eq 0 'Error' end if }
|
|||||||||||
15 Jul 2014, 20:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.