我有以下示例注释 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 中的答案也可以接受吗?

脚本.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/

10-11 16:50