linux – 如何格式化汇编注释
作者:互联网
我有以下示例评论GAS代码
cmpb $45, (%ebx) # 45 - ASCII '-'
jne r_filename
cmpb $118, 1(%ebx) # 118 - ASCII 'v'
jne r_filename
movl $4,%eax # write(
movl $1,%ebx # STDOUT,
movl $Leng, %edx # len *
movl $Inform, %ecx # *Buffer
int $0x80 # );
如何使用AWK格式化这样的注释:
cmpb $45, (%ebx) # 45 - ASCII '-'
jne r_filename
cmpb $118, 1(%ebx) # 118 - ASCII 'v'
jne r_filename
movl $4,%eax # write(
movl $1,%ebx # STDOUT,
movl $Leng, %edx # len *
movl $Inform, %ecx # *Buffer
int $0x80 # );
解决方法:
Perl的答案也可以接受吗?
script.pl:
#!/usr/bin/perl -w
while(<>) {
if(m/^(.+?)\s*(#.*)?$/) {
my ($code, $comment) = ($1, $2);
if($comment) {
printf "%- 40s %s\n", $code, $comment;
}
else {
print "$code\n";
}
}
else {
print;
}
}
叫它:
cat file.asm | perl script.pl
标签:linux,awk,perl,code-formatting 来源: https://codeday.me/bug/20190723/1514692.html