gpt4 book ai didi

assembly - 重定位被截断以适合 : R_386_8 against '.rodata'

转载 作者:行者123 更新时间:2023-12-03 06:25:18 32 4
gpt4 key购买 nike

尝试在 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

最佳答案

cmpb $a, (%eax) 导致错误。我猜您不想将 a 的内存地址与 (eax) 的值进行比较。顺便说一句:x86 中无法进行内存与内存的比较。我猜您想将 (eax) 处的字节与立即 ASCII 字符“a”(cmpb $97, (%eax))进行比较,您可以替换

a:      .byte   97          #a in ascii.

.equ a, 97

关于assembly - 重定位被截断以适合 : R_386_8 against '.rodata' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34370438/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com