尝试在x86 AT& T程序集中编译一个简单的字符串大小写交换函数时出现此错误。
我尝试使用此错误查看其他问题,但没有一个类似于我的情况下提供帮助。大多数人在不同的库和文件中处理事情,这不是这种情况。
错误:
$ gcc -m32 -g main.c test.s -o Test4
/tmp/ccQ49nKM.o: In function `scLOOP':
/home/nikolay/Dropbox/comporg/ex3/solution/test.s:24:(.text+0x14): relocation truncated to fit: R_386_8 against `.rodata'
collect2: error: ld returned 1 exit status
代码:
.section .rodata
.align 4
error: .string "invalid input!\n" # error message.
a: .byte 97 #a in ascii.
.text
.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 $a, (%eax) #compares first byte of string with a='a'.
jl scTOLOWER #byte is uppercase.
subb $32, (%eax) #byte is lowercase, change to uppercase.
jmp scINC #increment pointer.
scTOLOWER:
addb $32, (%eax) #change to lowercase.
jmp scINC #increment pointer.
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
答案 0 :(得分:-1)
你不必知道ascii表。 你可以做
a: .byte 'a'