2013-04-22 23 views
6

Tôi đã viết một chương trình NASM và tạo ra một tập tin danh sách từ nó bằng cách sử dụng nasm -f elf -l rs.lst rs.asm. Chương trình hoạt động hoàn hảo, có giá trị đầu vào chính và kết quả đầu ra cho dù giá trị là khóa điều khiển hoặc khóa có thể in và nếu đó là số, chữ thường hoặc chữ hoa.Làm thế nào để đọc một chương trình hội NASM .lst danh sách tập tin

Tôi cần trợ giúp để hiểu những gì tôi đang đọc trong tệp .lst. Các số trên các địa chỉ bên trái phải không? Hướng dẫn? DO chúng đại diện cho bộ nhớ? Đây là số .lst.

 1         segment .data 
     //Removed my student ID info        
    8          ;Program Output Strings 
    9         
    10 00000023 5072657373204B6579-   askForKey: db 'Press Key and Enter: ', 10 ; ;10 is the newline value 
    11 0000002C 20616E6420456E7465- 
    12 00000035 723A200A   
    13          askLen: equ $-askForKey 
    14         
    15 00000039 436F6E74726F6C204B-   controlKey: db 'Control Key ', 10 
    16 00000042 6579200A   
    17          controlLen: equ $-controlKey 
    18          
    19 00000046 5072696E7461626C65-   printableKey: db 'Printable Key ', 10 
    20 0000004F 204B6579200A  
    21          printableLen: equ $-printableKey 
    22         
    23 00000055 446563696D616C204B-   decimalKey: db 'Decimal Key ', 10 
    24 0000005E 6579200A   
    25          decimalLen: equ $-decimalKey 
    26         
    27 00000062 55707065722D636173-   upperKey: db 'Upper-case Key ', 10 
    28 0000006B 65204B6579200A  
    29          upperLen: equ $-upperKey 
    30         
    31 00000072 4C6F7765722D636173-   lowerKey: db 'Lower-case Key ', 10 
    32 0000007B 65204B6579200A  
    33          lowerLen: equ $-lowerKey 
    34          
    35 00000082 0A       blankLine: db '', 10 
    36          blankLen: equ $-blankLine 
    37         
    38         segment .bss 
    39         
    40 00000000 <res 00000002>    key resb 2 
    41         
    42         segment .text 
    43         
    44          global main 
    45         main: 
    46         
    47         
    48 00000000 B804000000     mov eax, 4  ; system call 4 
    49 00000005 BB01000000     mov ebx, 1  ; standard output 
    50 0000000A B9[00000000]    mov ecx, studentInfo ; 'Program by Raphael Stein' 
    51 0000000F BA23000000     mov edx, infoLen 
    52 00000014 CD80      int 0x80 
    53          
    54          ;Program Begins 
    55         
    56          ; Ask for key input 
    57 00000016 B804000000     mov eax, 4  ; system call 4 
    58 0000001B BB01000000     mov ebx, 1  ; standard output 
    59 00000020 B9[23000000]    mov ecx, askForKey ; 'Press key and Enter: ' 
    60 00000025 BA16000000     mov edx, askLen 
    61 0000002A CD80      int 0x80 
    62          ; Take input 
    63 0000002C B803000000     mov eax, 3 ; system call 3 to get input 
    64 00000031 BB00000000     mov ebx, 0 ; standart input device 
    65 00000036 B9[00000000]    mov ecx, key ; pointer to id 
    66 0000003B BA02000000     mov edx, 2 ; take in this many bytes 
    67 00000040 CD80      int 0x80  
    68         
    69         
    70          
    71         control:  ; check if it's a control key 
    72 00000042 B120      mov cl, 32 ; space bar (32) is the first key after control keys 
    73 00000044 BB[00000000]    mov ebx, key ;move the first 8bits of ebx for comparison 
    74 00000049 380B      cmp byte [ebx], cl ; compare 32 and the value of key 
    75 0000004B 7D1B      jge printable ; If the key is >=, it's a printable 
    76 0000004D B804000000     mov eax, 4 
    77 00000052 BB01000000     mov ebx, 1 
    78 00000057 B9[39000000]    mov ecx, controlKey 
    79 0000005C BA0D000000     mov edx, controlLen 
    80 00000061 CD80      int 0x80 
    81 00000063 E9A0000000     jmp exit ; It's obviously not any of the other categories 
    82         
    83          
    84         printable: ; Tell that it's a printable symbol 
    85 00000068 B804000000     mov eax, 4 
    86 0000006D BB01000000     mov ebx, 1 
    87 00000072 B9[46000000]    mov ecx, printableKey 
    88 00000077 BA0F000000     mov edx, printableLen 
    89 0000007C CD80      int 0x80 
    90         
    91         decimal: 
    92 0000007E B130      mov cl, 48 ; 0 (48) is the smallest decimal 
    93 00000080 BB[00000000]    mov ebx, key ;move the first 8bits of ebx for comparison 
    94 00000085 380B      cmp byte [ebx], cl 
    95 00000087 7C7F      jl exit 
    96 00000089 B139      mov cl, 57 ; 9 (57) is the largest decimal 
    97 0000008B BB[00000000]    mov ebx, key ;move the first 8bits of ebx for comparison 
    98 00000090 380B      cmp byte [ebx], cl 
    99 00000092 7F18      jg uppercase ; if key is greater, jump to check if it's      uppercase. 
    100 00000094 B804000000     mov eax, 4 
    101 00000099 BB01000000     mov ebx, 1 
    102 0000009E B9[55000000]    mov ecx, decimalKey 
    103 000000A3 BA0D000000     mov edx, decimalLen 
    104 000000A8 CD80      int 0x80 
    105 000000AA EB5C      jmp exit 
    106         
    107         uppercase: 
    108 000000AC B141      mov cl, 65 ; A (65) is the smallest smallest uppercase 
    109 000000AE BB[00000000]    mov ebx, key ;move the first 8bits of ebx for comparison 
    110 000000B3 380B      cmp byte [ebx], cl 
    111 000000B5 7C51      jl exit 
    112 000000B7 B15A      mov cl, 90 ; Z (90) is the largest upper case 
    113 000000B9 BB[00000000]    mov ebx, key ;move the first 8bits of ebx for comparison 
    114 000000BE 380B      cmp byte [ebx], cl 
    115 000000C0 7F18      jg lowercase 
    116 000000C2 B804000000     mov eax, 4 ; If it IS an upper case key, print and then exit 
    117 000000C7 BB01000000     mov ebx, 1 
    118 000000CC B9[62000000]    mov ecx, upperKey 
    119 000000D1 BA10000000     mov edx, upperLen 
    120 000000D6 CD80      int 0x80 
    121 000000D8 EB2E      jmp exit 
    122         
    123           
    124         lowercase: 
    125 000000DA B161      mov cl, 97 ; a (97) is the smallest smallest uppercase 
    126 000000DC BB[00000000]    mov ebx, key ;move the first 8bits of ebx for comparison 
    127 000000E1 380B      cmp byte [ebx], cl 
    128 000000E3 7C23      jl exit ; If the key is less than 97 exit. 
    129 000000E5 B17A      mov cl, 122 ; Z (90) is the largest upper case 
    130 000000E7 BB[00000000]    mov ebx, key ;move the first 8bits of ebx for comparison 
    131 000000EC 380B      cmp byte [ebx], cl 
    132 000000EE 7FEA      jg lowercase 
    133 000000F0 B804000000     mov eax, 4 ; If it IS an upper case key, print and then exit 
    134 000000F5 BB01000000     mov ebx, 1 
    135 000000FA B9[72000000]    mov ecx, lowerKey 
    136 000000FF BA10000000     mov edx, lowerLen 
    137 00000104 CD80      int 0x80 
    138 00000106 EB00      jmp exit 
    139          
    140         exit: 
    141 00000108 B804000000     mov eax, 4  ; system call 4 
    142 0000010D BB01000000     mov ebx, 1  ; standard output 
    143 00000112 B9[82000000]    mov ecx, blankLine ; Print blank line before exiting 
    144 00000117 BA01000000     mov edx, blankLen 
    145 0000011C CD80      int 0x80 
    146         
    147 0000011E B801000000     mov eax, 1 
    148 0000DB      xor ebx, ebx 
    149 00000125 CD80      int 0x80 
    150         

Trả lời

6

Các số ở bên trái là đầu ra nhị phân của bộ lắp ráp, liên quan đến dòng mã nguồn của bạn.

Cột đầu tiên là dòng mã nguồn

Cột thứ hai là địa chỉ hoặc bù đắp. Ví dụ: 00000023 là địa chỉ có nhãn nhắc askForKey: của bạn.

Cột thứ ba là giá trị nhị phân. Ví dụ, nếu bạn nhìn vào văn bản nhắc nhở của bạn Press nó chuyển trực tiếp đến giá trị hex 5072657373

52 00000014 CD80 int 0x80

đọc như thế này:

mã nguồn dòng 52, bù đắp 00.000.014 chứa CD80 giá trị nhị phân, biên soạn từ các hướng dẫn INT 0x80.

Bạn cũng có thể thấy đường tiếp theo mà có một địa chỉ bên cạnh nó là 57 00000016, nơi 16 đến là từ 14 trước + 2 byte cho CD80

+0

Nếu cột thứ hai là địa chỉ của lệnh , tại sao nó nhảy và không tăng lên một, hoặc một số nhất quán? – CodyBugstein

+0

@Imray vì không phải mọi dòng mã nguồn đều tạo ra cùng một số lượng kết quả được biên dịch - một số không tạo ra (bình luận) và một số sản xuất nhiều (db '....' có thể tạo ra độ dài tùy ý). ngăn xếp chúng từng cái một, tất cả các kích cỡ khác nhau bạn nhận được rằng 'nhảy' –

+0

Tại sao địa chỉ cho 'khóa'' 00000000'? – CodyBugstein

Các vấn đề liên quan