如何清理格式错误的x86_64程序集?

Dam*_*ira 3 assembly code-formatting x86-64

我有一些我想清理的集会.它具有全部大写,不一致的间距和许多不需要的换行符.

如何美化这个x86_64汇编代码?

ice*_*ord 5

我不知道任何具体的装配,但你提到的事情可以用sed完成.

有几点需要注意:

  • 助记符匹配正则表达式[A-Za-z0-9]+.在我的脑海中,我想不出任何包含其他角色的助记符.
  • GPR的上半部分匹配r(8|9|1[0-5])(b|w|d)
  • 字节GPR(不包括r8b-r15b)匹配 [abcd](l|h)|(sp|bp|si|di)l
  • 16位,32位和64位低8个GPR匹配 [er]?([abcd]x|sp|bp|si|di)
  • SSE寄存器可以与正则表达式匹配 xmm(1[0-5]?|[0,2-9])

例如:

# Replace tabs with spaces, then clean up lines of the form "op reg/imm, ..."
# N.B. without the /I option the match will be case-sensitive
sed 's/\t/ /g' <test.s | sed 's/^\s*\([a-z0-9][a-z0-9]*\)\s\s*\([a-z0-9][a-z0-9]*\)\s*,\s*/\t\1\t\2, /I'

# Lowercase all GPRs and SSE vector registers"
# I have chosen not to use the more compact patterns above in the interest of readability.
... | sed '/\([^a-z]\)\(AL|AH|AX|EAX|RAX|...XMM0|XMM1|...|XMM15\)/\1\L\2/gI'

# Lowercase all instruction mnemonics. More specifically, matches the first thing on every line except when it is followed by a colon.
... | sed '/^\s*\([a-z0-9][a-z0-9]*\)\([^:]\)/\L\1\2/I
Run Code Online (Sandbox Code Playgroud)