gpt4 book ai didi

Linux 汇编语言在编译无法识别的符号类型 square 时出现错误

转载 作者:太空宇宙 更新时间:2023-11-04 05:04:14 25 4
gpt4 key购买 nike

# Given a number, this program compute the square of a given function
# For Example the 2*2 is 4

#This program showa how to call a function recursively
.section .data
#This program has no global data

.section .text

.globl _start
.globl square #this is unneeded unless we need to share this program
#among others
_start:
pushl $4 #The function takes one argument_ the number we want
# square of . So it get pushed of.
call square #run the square function
addl $4, %esp # Scrubs the paramter that was pushed on the stack

movl %eax, %ebx #factorial returns the answer in %eax, but we want it #in %ebx to send it as the exit status
movl $1, %eax #call the kernel's next function
int $0x80

#This is a function that test square of a function
# It takes one argument and then return the square

.type square, @square
square:

pushl %ebp #standard function stuff -we have to
#restore %ebp to its prior state before
#returning, so we have to push it.
movl %esp,%ebp #This is because we don't want to modify
#the stack pointer, so we use %ebp
movl 8(%ebp), %eax #This moves the first argument to %eax
#4(%ebp) holds the return address, and
#8(%ebp) holds the first parameter.
cmpl $1,%eax #If the number is 1, that is our base
#case, and we simply return(1 is
#already in %eax as the return value.)
je end_square
pushl %eax #Push it for call to square
call square #call square
movl 8(%ebp),%ebx #%eax has the return value, so we
#reload or parameter into %ebx
imull %ebx,%eax #multiply that by the result of the last call
#to square(in %eax) the answer is stored in %eax,
#which is good since that's where return values go.
end_square:
movl %ebp, %esp # standard function stuff-we have to restore %ebp and
popl %ebp # %esp to where they were were before the function started
ret # return from the function (this pops the # return value, too)

最佳答案

尝试将:.type square, @square(这没有意义)替换为:.type square, @function

<小时/>

为了将来的引用 - 不要只在未格式化的代码转储上添加标题。您应该花时间阅读about该网站。

关于Linux 汇编语言在编译无法识别的符号类型 square 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21817835/

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