ATT X86程序集:警告:字符串未终止;从gcc插入换行符



我正在X86 AT&类赋值的T程序集。我单独测试了所有的函数,它们完全按照预期工作,但出于某种原因,我在标题中几乎每一行代码都收到了警告。由于各个函数都是在放在自己的文件中编译的,除了函数之外什么都没有,所以我真的不明白这里有什么错。请帮忙。

我是在14.04 Ubuntu上写的。

gcc -m32 -c pstring.s
pstring.s: Assembler messages:
pstring.s: Warning: end of file in string; '"' inserted
pstring.s:3: Warning: unterminated string; newline inserted
pstring.s:4: Warning: unterminated string; newline inserted
pstring.s:5: Warning: unterminated string; newline inserted
pstring.s:6: Warning: unterminated string; newline inserted
pstring.s:7: Warning: unterminated string; newline inserted
pstring.s:8: Warning: unterminated string; newline inserted
pstring.s:9: Warning: unterminated string; newline inserted
pstring.s:10: Warning: unterminated string; newline inserted
pstring.s:11: Warning: unterminated string; newline inserted
pstring.s:12: Warning: unterminated string; newline inserted
pstring.s:13: Warning: unterminated string; newline inserted
pstring.s:14: Warning: unterminated string; newline inserted
pstring.s:15: Warning: unterminated string; newline inserted
pstring.s:16: Warning: unterminated string; newline inserted
pstring.s:17: Warning: unterminated string; newline inserted
pstring.s:18: Warning: unterminated string; newline inserted
pstring.s:19: Warning: unterminated string; newline inserted
pstring.s:20: Warning: unterminated string; newline inserted
pstring.s:21: Warning: unterminated string; newline inserted
pstring.s:22: Warning: unterminated string; newline inserted
pstring.s:23: Warning: unterminated string; newline inserted
pstring.s:24: Warning: unterminated string; newline inserted
pstring.s:25: Warning: unterminated string; newline inserted
pstring.s:26: Warning: unterminated string; newline inserted
pstring.s:27: Warning: unterminated string; newline inserted
pstring.s:28: Warning: unterminated string; newline inserted
pstring.s:29: Warning: unterminated string; newline inserted
pstring.s:30: Warning: unterminated string; newline inserted
pstring.s:31: Warning: unterminated string; newline inserted
pstring.s:32: Warning: unterminated string; newline inserted
pstring.s:33: Warning: unterminated string; newline inserted
pstring.s:34: Warning: unterminated string; newline inserted
pstring.s:35: Warning: unterminated string; newline inserted
pstring.s:36: Warning: unterminated string; newline inserted
pstring.s:37: Warning: unterminated string; newline inserted
pstring.s:38: Warning: unterminated string; newline inserted
pstring.s:39: Warning: unterminated string; newline inserted
pstring.s:40: Warning: unterminated string; newline inserted
pstring.s:41: Warning: unterminated string; newline inserted
pstring.s:42: Warning: unterminated string; newline inserted
pstring.s:43: Warning: unterminated string; newline inserted
pstring.s:44: Warning: unterminated string; newline inserted
pstring.s:45: Warning: unterminated string; newline inserted
pstring.s:46: Warning: unterminated string; newline inserted
pstring.s:47: Warning: unterminated string; newline inserted
pstring.s:48: Warning: unterminated string; newline inserted
pstring.s:49: Warning: unterminated string; newline inserted
pstring.s:50: Warning: unterminated string; newline inserted
pstring.s:51: Warning: unterminated string; newline inserted
pstring.s:52: Warning: unterminated string; newline inserted
pstring.s:53: Warning: unterminated string; newline inserted
pstring.s:54: Warning: unterminated string; newline inserted
pstring.s:55: Warning: unterminated string; newline inserted
pstring.s:56: Warning: unterminated string; newline inserted
pstring.s:57: Warning: unterminated string; newline inserted
pstring.s:58: Warning: unterminated string; newline inserted
pstring.s:59: Warning: unterminated string; newline inserted
pstring.s:60: Warning: unterminated string; newline inserted
pstring.s:61: Warning: unterminated string; newline inserted
pstring.s:62: Warning: unterminated string; newline inserted
pstring.s:63: Warning: unterminated string; newline inserted
pstring.s:64: Warning: unterminated string; newline inserted
pstring.s:65: Warning: unterminated string; newline inserted
pstring.s:66: Warning: unterminated string; newline inserted
pstring.s:67: Warning: unterminated string; newline inserted
pstring.s:68: Warning: unterminated string; newline inserted
pstring.s:69: Warning: unterminated string; newline inserted
pstring.s:70: Warning: unterminated string; newline inserted
pstring.s:71: Warning: unterminated string; newline inserted
pstring.s:72: Warning: unterminated string; newline inserted
pstring.s:73: Warning: unterminated string; newline inserted
pstring.s:74: Warning: unterminated string; newline inserted
pstring.s:75: Warning: unterminated string; newline inserted
pstring.s:76: Warning: unterminated string; newline inserted
pstring.s:77: Warning: unterminated string; newline inserted
pstring.s:78: Warning: unterminated string; newline inserted
pstring.s:79: Warning: unterminated string; newline inserted
pstring.s:80: Warning: unterminated string; newline inserted
pstring.s:81: Warning: unterminated string; newline inserted
pstring.s:82: Warning: unterminated string; newline inserted
pstring.s:83: Warning: unterminated string; newline inserted
pstring.s:84: Warning: unterminated string; newline inserted
pstring.s:85: Warning: unterminated string; newline inserted
pstring.s:86: Warning: unterminated string; newline inserted
pstring.s:87: Warning: unterminated string; newline inserted
pstring.s:88: Warning: unterminated string; newline inserted
pstring.s:89: Warning: unterminated string; newline inserted
pstring.s:90: Warning: unterminated string; newline inserted
pstring.s:91: Warning: unterminated string; newline inserted
pstring.s:92: Warning: unterminated string; newline inserted
pstring.s:93: Warning: unterminated string; newline inserted
pstring.s:94: Warning: unterminated string; newline inserted
pstring.s:95: Warning: unterminated string; newline inserted
pstring.s:96: Warning: unterminated string; newline inserted
pstring.s:97: Warning: unterminated string; newline inserted
pstring.s:98: Warning: unterminated string; newline inserted
pstring.s:99: Warning: unterminated string; newline inserted
pstring.s:100: Warning: unterminated string; newline inserted
pstring.s:101: Warning: unterminated string; newline inserted
pstring.s:102: Warning: unterminated string; newline inserted
pstring.s:103: Warning: unterminated string; newline inserted
pstring.s:104: Warning: unterminated string; newline inserted
pstring.s:105: Warning: unterminated string; newline inserted
pstring.s:106: Warning: unterminated string; newline inserted
pstring.s:107: Warning: unterminated string; newline inserted
pstring.s:108: Warning: unterminated string; newline inserted
pstring.s:109: Warning: unterminated string; newline inserted
pstring.s:110: Warning: unterminated string; newline inserted
pstring.s:111: Warning: unterminated string; newline inserted
pstring.s:112: Warning: unterminated string; newline inserted
pstring.s:113: Warning: unterminated string; newline inserted
pstring.s:114: Warning: unterminated string; newline inserted
pstring.s:115: Warning: unterminated string; newline inserted
pstring.s:116: Warning: unterminated string; newline inserted
pstring.s:117: Warning: unterminated string; newline inserted
pstring.s:118: Warning: unterminated string; newline inserted
pstring.s:119: Warning: unterminated string; newline inserted
pstring.s:120: Warning: unterminated string; newline inserted
pstring.s:121: Warning: unterminated string; newline inserted
pstring.s:122: Warning: unterminated string; newline inserted
pstring.s:123: Warning: unterminated string; newline inserted
pstring.s:124: Warning: unterminated string; newline inserted
pstring.s:125: Warning: unterminated string; newline inserted
pstring.s:126: Warning: unterminated string; newline inserted
pstring.s:127: Warning: unterminated string; newline inserted
pstring.s:128: Warning: unterminated string; newline inserted
pstring.s:129: Warning: unterminated string; newline inserted
pstring.s:130: Warning: unterminated string; newline inserted
pstring.s:131: Warning: unterminated string; newline inserted
pstring.s:132: Warning: unterminated string; newline inserted
pstring.s:133: Warning: unterminated string; newline inserted
pstring.s:134: Warning: unterminated string; newline inserted
pstring.s:135: Warning: unterminated string; newline inserted
pstring.s:136: Warning: unterminated string; newline inserted
pstring.s:137: Warning: unterminated string; newline inserted
pstring.s:138: Warning: unterminated string; newline inserted
pstring.s:139: Warning: unterminated string; newline inserted
pstring.s:140: Warning: unterminated string; newline inserted
pstring.s:141: Warning: unterminated string; newline inserted
pstring.s:142: Warning: unterminated string; newline inserted
pstring.s:143: Warning: unterminated string; newline inserted
pstring.s:144: Warning: unterminated string; newline inserted
pstring.s:145: Warning: unterminated string; newline inserted
pstring.s:146: Warning: unterminated string; newline inserted
pstring.s:147: Warning: unterminated string; newline inserted
pstring.s:148: Warning: unterminated string; newline inserted
pstring.s:149: Warning: unterminated string; newline inserted
pstring.s:150: Warning: unterminated string; newline inserted
pstring.s:151: Warning: unterminated string; newline inserted
pstring.s:152: Warning: unterminated string; newline inserted
pstring.s:153: Warning: unterminated string; newline inserted
pstring.s:154: Warning: unterminated string; newline inserted
pstring.s:155: Warning: unterminated string; newline inserted
pstring.s:156: Warning: unterminated string; newline inserted
pstring.s:157: Warning: unterminated string; newline inserted
pstring.s:158: Warning: unterminated string; newline inserted
pstring.s:159: Warning: unterminated string; newline inserted
pstring.s:160: Warning: unterminated string; newline inserted
pstring.s:161: Warning: unterminated string; newline inserted
pstring.s:162: Warning: unterminated string; newline inserted
pstring.s:163: Warning: unterminated string; newline inserted
pstring.s:164: Warning: unterminated string; newline inserted
pstring.s:165: Warning: unterminated string; newline inserted
pstring.s:166: Warning: unterminated string; newline inserted
pstring.s:167: Warning: unterminated string; newline inserted
pstring.s:168: Warning: unterminated string; newline inserted
pstring.s:169: Warning: unterminated string; newline inserted
pstring.s:170: Warning: unterminated string; newline inserted
pstring.s:171: Warning: unterminated string; newline inserted
pstring.s:172: Warning: unterminated string; newline inserted
pstring.s:173: Warning: unterminated string; newline inserted
pstring.s:174: Warning: unterminated string; newline inserted
pstring.s:175: Warning: unterminated string; newline inserted
pstring.s:176: Warning: unterminated string; newline inserted
pstring.s:177: Warning: unterminated string; newline inserted
pstring.s:178: Warning: unterminated string; newline inserted
pstring.s:179: Warning: unterminated string; newline inserted
pstring.s:180: Warning: unterminated string; newline inserted
pstring.s:181: Warning: unterminated string; newline inserted
pstring.s:182: Warning: unterminated string; newline inserted
pstring.s:183: Warning: unterminated string; newline inserted
pstring.s:184: Warning: unterminated string; newline inserted
pstring.s:185: Warning: unterminated string; newline inserted
pstring.s:186: Warning: unterminated string; newline inserted
pstring.s:187: Warning: unterminated string; newline inserted
pstring.s:188: Warning: unterminated string; newline inserted
pstring.s:189: Warning: unterminated string; newline inserted
pstring.s:190: Warning: unterminated string; newline inserted
pstring.s:191: Warning: unterminated string; newline inserted
pstring.s:192: Warning: unterminated string; newline inserted
pstring.s:193: Warning: unterminated string; newline inserted
pstring.s:194: Warning: unterminated string; newline inserted
pstring.s:195: Warning: unterminated string; newline inserted
pstring.s:196: Warning: unterminated string; newline inserted
pstring.s:197: Warning: unterminated string; newline inserted
pstring.s:198: Warning: unterminated string; newline inserted
pstring.s:199: Warning: unterminated string; newline inserted
pstring.s:200: Warning: unterminated string; newline inserted
pstring.s:201: Warning: unterminated string; newline inserted
pstring.s:202: Warning: unterminated string; newline inserted
pstring.s:203: Warning: unterminated string; newline inserted
pstring.s:204: Warning: unterminated string; newline inserted
pstring.s:205: Warning: unterminated string; newline inserted
pstring.s:206: Warning: unterminated string; newline inserted
pstring.s:207: Warning: unterminated string; newline inserted
pstring.s:208: Warning: unterminated string; newline inserted
pstring.s:209: Warning: unterminated string; newline inserted
pstring.s:210: Warning: unterminated string; newline inserted
pstring.s:211: Warning: unterminated string; newline inserted
pstring.s:212: Warning: unterminated string; newline inserted
pstring.s:213: Warning: unterminated string; newline inserted
pstring.s:214: Warning: unterminated string; newline inserted
pstring.s:215: Warning: unterminated string; newline inserted
pstring.s:216: Warning: unterminated string; newline inserted
pstring.s:217: Warning: unterminated string; newline inserted
pstring.s:218: Warning: unterminated string; newline inserted
pstring.s:219: Warning: unterminated string; newline inserted
pstring.s:220: Warning: unterminated string; newline inserted
pstring.s:221: Warning: unterminated string; newline inserted
pstring.s:222: Warning: unterminated string; newline inserted
pstring.s:223: Warning: unterminated string; newline inserted
pstring.s:224: Warning: unterminated string; newline inserted
pstring.s:225: Warning: unterminated string; newline inserted
pstring.s:226: Warning: unterminated string; newline inserted
pstring.s:227: Warning: unterminated string; newline inserted
pstring.s:228: Warning: unterminated string; newline inserted
pstring.s:229: Warning: unterminated string; newline inserted
pstring.s:230: Warning: unterminated string; newline inserted
pstring.s:231: Warning: unterminated string; newline inserted
pstring.s:232: Warning: unterminated string; newline inserted
pstring.s:233: Warning: unterminated string; newline inserted
pstring.s:234: Warning: unterminated string; newline inserted
pstring.s:235: Warning: unterminated string; newline inserted

321123242 Nikolay Babkin
    .section    .rodata
error:      .string "invalid input!n'  # error message.
    .text
    .global pstrlen         #receives a pointer to a pstring as argument.
    .type pstrlen, @function    #returns the length as a byte.
pstrlen:
    pushl   %ebp            #save old FP.
    movl    %esp, %ebp      #set new FP.
    movl    8(%ebp), %eax       #retrieve pointer to pstring.   
    movb    (%eax), %al     #copy the first byte of the argument into %al
    movzbl  %al, %eax       #Zero-fill the other 3 bytes of the register.
    movl    %ebp, %esp      #restore the old stack pointer - release all used memory.
    popl    %ebp            #restore old frame pointer (the caller function frame)
    ret             #return to caller function
    .global replaceChar     #receives a pointer to a pstring, a oldChar byte and a newChar byte as arguments.
    .type replaceChar, @function    #replaces all oldChars with newChars and returns the pointer to the pstring
replaceChar:
    pushl   %ebp            #save old FP
    movl    %esp, %ebp      #set new FP
    pushl   %ebx            #save %ebx on stack
    movl    8(%ebp), %eax       #get the pstring pointer from the stack.
    movb    (%eax), %bh     #retrieved the len of the pstring
    addl    $1, %eax        #align the pointer to point to the string itself
    movl    12(%ebp), %ecx      #get the oldChar argument.
    movb    %cl, %dl        #store oldChar in %dl
    movl    16(%ebp), %ecx      #get the newChar argument.
    movb    %cl, %dh        #store newChar in %dh
    movb    $0, %bl         #initialize count register to 1.
    rcTEST:
    cmpb    %bh, %bl        #Test
    je  rcDONE          #if Test: goto done
    rcLOOP:             #loop label
    cmpb    %dl, (%eax)     #compare the current byte to the oldChar byte
    je  rcCHANGE        #jump to change the oldChar.
    rcINCREMENT:            #label for incrementing the current char and the count variable.
    add $1, %bl         #increment the count
    add $1, %eax        #increment the string pointer one byte.
    jmp rcTEST          #Don't want no infinite loops causing segmentation faults, do we?
    rcCHANGE:
    movb    %dh, (%eax)     #overwrite the oldChar with a newChar
    jmp rcINCREMENT     #move on with the loop mechanism
    rcDONE:
    mov 8(%ebp), %eax       #set return value to be the pstring pointer.
    popl    %ebx            #restore %ebx register.
    movl    %ebp, %esp      #restore the old stack pointer - release all used memory.
    popl    %ebp            #restore old frame pointer (the caller function frame)
    ret             #return to caller function
    .global pstrijcpy
    .type   pstrijcpy, @function
pstrijcpy:
    pushl   %ebp            #save old FP
    movl    %esp, %ebp      #set new FP
#using eax, ebx, ech, edx, 
    pushl   %ebx            #back %ebx up.
    movl    16(%ebp), %eax      #the dword with i
    movb    %al, %bl        #store i in %bl
    movl    20(%ebp), %eax      #the dword with j
    movb    %al, %bh        #store j in %bh
    movl    8(%ebp), %eax       #initialize eax to dst ptr.
    movb    (%eax), %dh     #%dh <- dst.len
    addl    $1, %eax        #advance %eax by one byte to the string
    movl    12(%ebp), %ecx      #initialize ecx to src ptr.
    mov (%ecx), %dl     #%dl <- src.len
    addl    $1, %ecx        #advance %ecx by one byte to the string
    cmpb    %dl, %bl        #i-src.len
    jg  cpyERROR        #if >: goto error
    cmp %dl, %bh        #j-src.len
    jg  cpyERROR        #if >: goto error
    cmpb    %dh, %bl        #i-dst.len
    jg  cpyERROR        #if >: goto error
    cmp %dh, %bh        #j-dst.len
    jg  cpyERROR        #if >: goto error
    #now I will add i to the pointers that point to the strings.
    push    %edx            #back edx up
    movzbl  %bl, %edx       #apparently I can use 'movl %bl, %eax', so I did this.
    addl    %edx, %eax      #advance dst to ith character
    addl    %edx, %ecx      #advance src to ith character
    popl    %edx            #restore edx
    cpyTEST:
    cmpb    %bh, %bl        #compare i with j
    jg  cpyDONE         #once i is greater than j, we are done.
    cpyLOOP:
    movb    (%ecx), %dl     #Since I already checked that i and j <= the lengths, I can use them
    movb    %dl, (%eax)     #Move byte from src to dst.
    addl    $1, %ecx        #Increment src to next byte
    addl    $1, %eax        #Increment dst to next byte
    addl    $1, %ebx        #Increment i by 1.
    jmp cpyTEST         #goto test
    cpyERROR:           #don't need to back registers up.
    pushl   $error          #push the message to be printed.
    call    printf          #use printf to print error message
    cpyDONE:
    popl    %ebx            #restore %ebx
    movl    8(%ebp), %eax       #set return value to be dst pointer.
    movl    %ebp, %esp      #restore the old stack pointer - release all used memory.
    popl    %ebp            #restore old frame pointer (the caller function frame)
    ret             #return to caller function
    .global swapCase        #swaps the cases of the string.
    .type   swapCase, @function
swapCase:
    pushl   %ebp            #save old FP
    movl    %esp, %ebp      #set new FP
    movl    8(%ebp), %eax       #get pointer to pstring
    movb    (%eax), %cl     #get length of pstring
    addl    $1, %eax        #move pointer to string itself
    scLTEST:            #loop condition.
    cmpb    $0, %cl         #compare length with 0
    je  scDONE          #if length is zero, goto done
    jmp scLOOP          #else: goto loop
    scLOOP:
    cmpb    $97, (%eax)     #compares first byte of string with 'a'.
    jge scTRYLOWER      #byte is lowercase-possible.
    cmpb    $90, (%eax)     #compares first byte of string with 'Z'.
    jle scTRYUPPER      #byte is uppercase-possible.
    jmp scINC           #byte is between 65 and 97, so not a letter.
    scTRYUPPER:         #checking if byte is really upper-case.
    cmpb    $65, (%eax)     #compare byte with 'A'.
    jge scCHANGETOLOWER     #if byte is 'A' or after, it is upper-case, so change to lower-case.
    jmp scINC           #otherwise, it is below 'A' and is thus not a letter.
    scTRYLOWER:
    cmpb    $122, (%eax)        #compare byte with 'z'.
    jle scCHANGETOUPPER     #if it is before or at 'z', it is a lower-case letter.
    jmp scINC           #otherwise, it is over 'z' and not a letter.
    scCHANGETOUPPER:
    subb    $32, (%eax)     #reduce the byte from range [97,122] to [65,90]
    jmp scINC
    scCHANGETOLOWER:
    addb    $32, (%eax)     #increase the byte to range [97,122] from [65,90]
    #jmp    scINC           #for now, the jump is not necessary since the increment stage is already after it.
    scINC:
    addl    $1, %eax        #increment %eax to next byte
    decb    %cl         #decrement counter
    jmp scLTEST         #end current loop iteration
    scDONE:
    movl    8(%ebp), %eax       #set return value to pointer to pstring.
    movl    %ebp, %esp      #restore old stack pointer
    popl    %ebp            #restore old FP
    ret             #return to caller function
    .global pstrijcmp       #compares pstring1 and pstring 2 in range i to j.
    .type   pstrijcmp, @function    #returns -1 if pstring1 < pstring2, 0 if equal and 1 if greater. -2 is error value.
pstrijcmp:
    pushl   %ebp            #save old FP
    movl    %esp, %ebp      #set new FP
    pushl   %ebx            #back %ebx up.
    movl    16(%ebp), %eax      #retrieve the dword with i.
    movb    %al, %ch        #set %ch to be i.
    movl    20(%ebp), %eax      #retrieve the dword with j.
    movb    %al, %cl        #set %cl to be j.
    movl    8(%ebp), %eax       #set pstring1ptr into eax.
    movl    12(%ebp), %edx      #set pstring2ptr into edx.
    cmpb    (%eax), %ch     #i-str1.len
    jg  cmpERROR        #if i>len: goto error
    cmp (%eax), %cl     #j-str1.len
    jg  cmpERROR        #if jlen>: goto error
    cmpb    (%edx), %ch     #i-str2.len
    jg  cmpERROR        #if i>len2: goto error
    cmp (%edx), %cl     #j-str2.len
    jg  cmpERROR        #if j>len2: goto error
    incl    %eax            #increment eax to get past the length byte
    incl    %edx            #increment edx to get past the length byte
    cmpTEST:
    cmpb    %cl, %ch        #compare i with j
    jg  cmpPREDONE          #goto done once i>j
    #jmp    cmpLOOP         #else: goto loop
    cmpLOOP:
    movb    (%eax), %bl     #take current str1 byte into %bl
    cmpb    %bl, (%edx)     #compare %bl with first %edx byte
    je  cmpINC          #if same: increment phase.
    jl  cmpLESS         #str1 is before str2 lexicographically.
    movl    $1, %eax        #set return value to 1.
    jmp cmpDONE         #done.
    cmpLESS:
    movl    $-1, %eax       #set return value to -1
    jmp cmpDONE         #done
    cmpINC:
    incl    %eax            #increment str1 pointer.
    incl    %edx            #increment str2 pointer.
    incb    %ch         #i++
    jmp cmpTEST         #current loop iteration is over.
    cmpERROR:           #don't need to back registers up.
    pushl   $error          #push the message to be printed.
    call    printf          #use printf to print error message
    movl    $-2, %eax       #set return value to -2
    jmp cmpDONE
    cmpPREDONE:
    movl    $0, %eax        #set return value to 0.
    cmpDONE:
    popl    %ebx            #restore old %ebx
    movl    %ebp, %esp      #restore old stack pointer
    popl    %ebp            #restore old FP
    ret             #return to caller function

错误出现在第3行,如消息所示。您有"string'而不是"string"。(注意最后的引号)。

此外,像cmpb指令上的"Test"这样的注释也是无用的。您应该评论为什么代码做它所做的事情,或者至少涉及哪些数据。我知道写一些读起来像insn-ref手册的评论很诱人,但不要。

movb $0, %bl #initialize count register to 1.特别有趣。

此外,将代码缩进到比标签多一级的位置,使它们脱颖而出。

x86 wiki有很多不错的链接,顺便说一句,

最新更新