Created
June 7, 2012 09:53
-
-
Save geekman/2887924 to your computer and use it in GitHub Desktop.
assembles short ARM instructions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # | |
| # assembles a short ARM assembly file/line and shows the opcode + disassembly | |
| # useful for compiling one-liners into opcode | |
| # | |
| # usage: | |
| # arm_asm src-file.S -> assembles src-file.S | |
| # echo "mov r1, r4" | arm_asm -> assemble a single instruction | |
| # | |
| ASM_FILE=$1 | |
| GCC=${GCC:-/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2} | |
| # check gcc | |
| hash "$GCC" 2> /dev/null || { | |
| echo "unable to find gcc - please specify it in GCC" | |
| exit 2 | |
| } | |
| # check for file, or read from stdin | |
| ASM_FILE_TEMP= | |
| if [ -z "$ASM_FILE" ]; then | |
| ASM_FILE_TEMP=`mktemp /var/tmp/testarm.XXXXXXXXXXX` | |
| cat > $ASM_FILE_TEMP | |
| ASM_FILE="$ASM_FILE_TEMP" | |
| fi | |
| # compile | |
| OUTPUTS= | |
| for ARMV in 6 7; do | |
| TMPOUT=`mktemp /var/tmp/testarm${ARMV}.XXXXXXXXXXX` | |
| $GCC -arch armv$ARMV -D_ARM_ARCH_$ARMV -c -o $TMPOUT -x assembler $ASM_FILE | |
| OUTPUTS="$OUTPUTS $TMPOUT" | |
| done | |
| # create fat binary and disassemble it | |
| TMP_O_FAT=`mktemp /var/tmp/testarm_fat.XXXXXXXXXXX` | |
| lipo -create $OUTPUTS -output $TMP_O_FAT | |
| otool -t -v $TMP_O_FAT | |
| rm -f $TMP_O_FAT $OUTPUTS $ASM_FILE_TEMP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment