Advertisement
Guest User

sed script for converting gcc intel asm to nasm

a guest
Nov 17th, 2013
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.41 KB | None | 0 0
  1. sed \
  2.     `#########################################################` \
  3.     `###### Rename statements to their Nasm equivalents ######` \
  4. -e 's|\.string|db|g'    `# .string lines are essentially combination bytes              ` \
  5. -e 's|\.byte|db|g'  `# .byte data is just... a byte                         ` \
  6. -e 's|\.long|dd|g'  `# .long data is double                             ` \
  7. -e 's|\.zero|resb|g'    `# gcc puts .zero lines where a byte should be reserved - not sure      ` \
  8. -e 's|\.align|align|g'  `# align works the same way in gcc and nasm                 ` \
  9. -e 's|\.L|L|g'      `# Labels in gcc,s intel syntax start with .L - remove the dot for simplicity   ` \
  10. -e 's|main|_start|g'    `# If we are going to use ld for linking, _start should be the entry point  ` \
  11.     `###################################`\
  12.     `###### Pointer modifications ######`\
  13. -e 's|PTR ||g'          `# Pointers in nasm dont need the word PTR` \
  14. -e 's|OFFSET FLAT:|dword |g'    `# Nasm doesnt understand flat pointers. They are same as double ptrs` \
  15.     `# Pointers in Nasm require [] around them  `\
  16.     `# For example, convert             `\
  17.     `#      ....QWORD player+40     `\
  18.     `# to                       `\
  19.     `#      ....QWORD [player+40]       `\
  20. -e 's|BYTE \([a-zA-Z][a-zA-Z0-9+\._]*\)|BYTE \[\1\]|g' \
  21. -e 's|QWORD \([a-zA-Z][a-zA-Z0-9+\._]*\)|QWORD \[\1\]|g' \
  22. -e 's|DWORD \([a-zA-Z][a-zA-Z0-9+\._]*\)|DWORD \[\1\]|g' \
  23.     `###############################################################`\
  24.     `###### Remove lines which contain the following patterns ######`\
  25. -e '/^\t\.cfi/d' \
  26. -e '/^\t\.local/d' \
  27. -e '/^\t\.file/d' \
  28. -e '/^\t\.intel_syntax/d' \
  29. -e '/^\t\.globl/d' \
  30. -e '/^\t\.size/d' \
  31. -e '/^\t\.type/d' \
  32. -e '/^\t\.ident/d' \
  33. -e '/^LFE/d' `# Labels starting with LFE and LFB are not used anywhere in the file. Why bother?`\
  34. -e '/^LFB/d' \
  35. -e '/\.note/d' \
  36.     `############################################################` \
  37.     `###### Rename st* registers to their Nasm equivalents ######` \
  38. -e 's|st(0)|st0|g'  \
  39. -e 's|st(1)|st1|g' \
  40. -e 's|st(2)|st2|g' \
  41. -e 's|st(3)|st3|g' \
  42. -e 's|st(4)|st4|g' \
  43. -e 's|st(5)|st5|g' \
  44. -e 's|st(6)|st6|g' \
  45. -e 's|st,|st0,|g' \
  46. -e 's|st$|st0|g' \
  47.     `#############################################################`\
  48.     `###### Rename .comm lines to their nasm equivalent ######`\
  49.     `###### For example, convert                ######`\
  50.     `######    .comm    time_old.15416,8,8      ######`\
  51.     `###### to                      ######`\
  52.     `######    common   ret_val.15417 8:8       ######`\
  53. -e 's|^\t.comm\(.*\),\([0-9]\),\([0-9]\)|\tcommon \1 \2:\3|g'  \
  54. main.intel-gcc.s > main.nasm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement