linux - 如何格式化程序集注释

标签 linux perl awk code-formatting

我有以下示例注释 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 - 如何格式化程序集注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7984960/

相关文章:

perl - "map"是循环吗?

bash - 使用 Awk 提取子串

awk - 在awk中使用填充将数字转换为字符串

linux - awk 拆分文件给出不完整的行

Arm Cortex-M1 上的 Linux

perl - 禁用关于 qw 列表中文字逗号的警告

json - 在没有尾随分隔符的情况下分隔 AWK 中的输出记录

c++ - 解决 GNU 中重新声明的链接器错误

python - 使python进程写入立即安排回写而不被标记为脏

ajax - 从 ubuntu 服务器向浏览器推送数据