我想要清理一些装配。它具有全部大写,不一致的间距和许多不需要的换行符。
如何美化此x86_64汇编代码?
答案 0 :(得分:5)
我不知道汇编的具体内容,但你提到的事情可以用sed完成。
有几点需要注意:
[A-Za-z0-9]+
匹配。我无法想到任何包含其他角色的助记符。r(8|9|1[0-5])(b|w|d)
?[abcd](l|h)|(sp|bp|si|di)l
[er]?([abcd]x|sp|bp|si|di)
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