我是组装的新手,我一直在尝试学习随机问题。我在Linux机器上使用nasm 64位。我一直在尝试生成斐波那契数列。但是,当我运行可执行文件时,出现段错误(核心转储)错误。
section .data
input db 2
section .bss
fib resb 128
section .text
_start:
mov rax, 1
mov rcx, 1
mov rdx, fib
mov rdx, 1
inc rdx
mov rbx, 0
call _fibLoop
call _fibPrint
mov rax, 60
mov rdi, 0
syscall
_fibLoop:
mov [rdx], rax
inc rdx
add rcx, rax
push rcx
mov rcx, [rax]
pop rax
inc rbx
cmp rbx, [input]
jne _fibLoop
ret
我知道_fibPrint的调用不是问题,因为它实际上什么也不做。我认为写入保留内存的方式有缺陷。但是,我过去也能够类似地执行此操作,因此我错失了什么。
答案 0 :(得分:3)
作为初始化的一部分,您将具有以下顺序:
<CFAPPLICATION
NAME="catholicity"
SESSIONMANAGEMENT="Yes"
SESSIONTIMEOUT=#CreateTimeSpan(0,2,0,0)#
CLIENTMANAGEMENT="Yes"
CLIENTSTORAGE="Cookie"
>
<cfif structKeyExists(session,"cfid")>
<cfcookie name="cfid" value="#session.cfid#" expires="NOW">
<cfcookie name="cftoken" value="#session.cftoken#" expires="NOW">
</cfif>
<cfif structKeyExists(url, "logout")>
<cfset session.user.authenticated = 0>
</cfif>
<cfparam name="session.cfid" default="">
<cfparam name="session.cftoken" default="">
<cfparam name="session.mode" default="temp">
<cfparam name="session.user.authenticated" default="0">
<cfparam name="session.user.confirmed" default="0">
<cfparam name="session.user.disabled" default="0">
<cfparam name="session.user.id" default="">
<cfparam name="session.user.email" default="">
<cfparam name="session.user.contact_name" default="">
<cferror type="exception" template="/error.cfm">
<cfscript>
application.accepted_docs = "application/pdf,application/msword,application/vnd.ms-excel,text/plain,vnd.ms-word.document.12,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
application.accepted_images = "image/jpg,image/gif,image/jpeg,image/png,image/x-png,image/pjpeg ";
application.accepted_videos = "video/x-flv,video/mp4,video/x-msvideo,video/x-ms-asf,video/x-ms-wmv,audio/x-ms-wma";
....
</cfscript>
<cflock name="#APPLICATION.applicationName#"
type="Exclusive"
timeout="20"
throwontimeout="Yes">
<cfparam name="APPLICATION.SessionTracker" default=#StructNew()#>
<cfscript>
sUserInfo = StructNew();
sUserInfo.Address="#CGI.REMOTE_ADDR#";
sUserInfo.CFID="#session.cfid#";
sUserInfo.Token="#session.cftoken#";
sUserInfo.Address="#CGI.REMOTE_ADDR#";
sUserInfo.Time="#Now()#";
sUserInfo.Template="#CGI.CF_Template_Path#";
ID = "#session.cfid##session.cftoken#";
</cfscript>
<CFSET dummy = StructInsert(APPLICATION.SessionTracker, ID, sUserInfo, true)>
</cflock>
这将使mov rdx, fib
mov rdx, 1
inc rdx
的值为rdx
,而不是保留数字的缓冲区的偏移量。然后,在2
的开头,您使用
_fibLoop
这将尝试访问您无法访问的内存,从而导致分段错误。
我认为在mov [rdx], rax
之后删除多余的两行将解决该崩溃问题,使您可以继续使用GDB或所需的其他调试器调试其他错误。
(就像mov rdx,fib
中的inc rdx
仅将指针前移1个字节,但是您要存储8个字节。_fibLoop
也是1个字节,但是您也在那里进行8字节加载。)