IOS ARM assembly - Convert x86 to ARM

Discussion in 'iOS Programming' started by alexmalex021, Sep 19, 2015.

  1. alexmalex021, Sep 19, 2015
    Last edited: Sep 19, 2015

    alexmalex021 macrumors newbie

    Joined:
    May 19, 2015
    #1
    Hello All,

    How can i convert x86 assembly to ARM(in IOS)? or how write assembly code for IOS to call a syscall.

    *** UPDATE

    Another question : How can i write an ARM assembly code and create binary file in OS X and run in iPhone? can i use iphone SDK as? i use that tool but got an error

    UPDATE ***

    for example :

    Code:
    ;File: hello.asm;Build: nasm -f macho hello.asm&& gcc -o hello hello.o
    
    SECTION .rodata
    hello.msg db 'Hello, World!',0x0a,0x00
    
    SECTION .text
    
    extern _printf ; could also use _puts...
    GLOBAL _main
    
    ; aligns esp to 16 bytes in preparation for calling a C library function; arg is number of bytes to pad forfunction arguments,this should be a multiple of 16;unless you are using push/pop to load args%macro clib_prolog 1
    mov ebx, esp ; remember current esp
    and esp,0xFFFFFFF0; align to next16byte boundary (could be zero offset!)sub esp,12; skip ahead 12 so we can store original esp
    push ebx ; store esp (16 bytes aligned again)sub esp,%1; pad for arguments (make conditional?)%endmacro
    
    ; arg must match most recent call to clib_prolog%macro clib_epilog 1
    add esp,%1; remove arg padding
    pop ebx ;get original esp
    mov esp, ebx ; restore
    %endmacro
    
    _main:;set up stack frame
    push ebp
    mov ebp, esp
    push ebx
    
    clib_prolog 16
    mov dword [esp], hello.msg
    call _printf
    ; can make more clib calls here...
    clib_epilog 16
    
    ; tear down stack frame
    pop ebx
    mov esp, ebp
    pop ebp
    mov eax,0;setreturn code
    ret
    
     
  2. Floris macrumors 68020

    Floris

    Joined:
    Sep 7, 2007
    Location:
    Netherlands
    #2
    Do you have experience coding iOS apps in Swift using XCode?
     
  3. alexmalex021 thread starter macrumors newbie

    Joined:
    May 19, 2015
  4. MarkCollette macrumors 68000

    MarkCollette

    Joined:
    Mar 6, 2003
    Location:
    Toronto, Canada
    #4
    Your x86 assembly is just calling functions, and likely ARM uses a different convention for calling conventions, so it doesn't really look like it's useful code to convert anyways. Why not just code it in C / Objective-C ?
     
  5. alexmalex021 thread starter macrumors newbie

    Joined:
    May 19, 2015
    #5
    Hi Mark,

    My code is only a sample code.and i want to know about process of converting from x86 to ARM.how change registers,how use syscalls and ...

    Regards
     
  6. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #7
    You can write your library call in C or Objective C, build an app using that call with Xcode, then use the Xcode debug, debug workflow, show assembly feature to see either the x86 (Sim) or ARM (device) assembly code.
     

Share This Page