我正在尝试获取通过ARM中的命令行传递的字符串的长度-以下代码有效,但随后返回import random
class Bug:
def __init__(self, number, xPos, yPos, placement, worldXSize=80, worldYSize=80):
# the environment
self.number = number
self.worldXSize = worldXSize
self.worldYSize = worldYSize
# the bug
self.xPos = xPos
self.yPos = yPos
print("Bug number ", self.number,
" has been created at ", self.xPos, ", ", self.yPos)
# the action
def randomWalk(self):
self.xPos += randomMove()
self.yPos += randomMove()
self.xPos = (self.xPos + self.worldXSize) % self.worldXSize
self.yPos = (self.yPos + self.worldYSize) % self.worldYSize
# report
def reportPosition(self):
print("Bug number ", self.number, " moved to X = ",
self.xPos, " Y = ", self.yPos)
def placement(self):
self.xPos = self.xPos % self.worldXSize + randomMove()
def randomMove():
return random.randint(-1, 1)
错误:
core dumped
我在做什么错了?
答案 0 :(得分:1)
您在main
的末尾缺少返回指令,因此在函数结束时,CPU只是继续执行内存中的下一个内容。无法预测这将产生什么效果,但是永远不会好!
您也不会弹出您推送的寄存器,您可以在将返回的lr
的弹出值直接弹出到pc
的同时执行此操作:
POP {r4-r8,pc}