NASM X86 中的分段错误

问题描述 投票:0回答:1
assembly
section .data
    playerLives: dd 5
    gameOver: dd 0
    timesReset: dd 0
    playerY: dd 5
    playerX: dd 5
    playerScore: dd 0

   section .text
   global _start
   global _completeReset
   global _resetGame
   global _resetCMP
   global _checkPlayerScore

   _start:
    cmp dword [gameOver], 1
    je _resetCMP

_resetCMP:
    add dword [timesReset], 1
    cmp dword [timesReset], 4
    je _completeReset
    jl _reset

_completeReset:
    mov dword [playerLives], 10
    mov dword [gameOver], 0
    mov dword [timesReset], 0
    mov dword [playerX], 5
    mov dword [playerY], 5
    mov dword [playerScore], 0

_reset:
    mov dword [playerLives], 5
    mov dword [timesReset], 0
    mov dword [playerScore], 0
    mov dword [gameOver], 0

此代码将重置,完全重置,比较我的游戏的代码变量。 这最终将是玩家逻辑,但正如你所看到的,我遇到了一个错误,希望我能得到一些帮助。

如果是这样,感谢您的帮助,如果我的问题已解决,我将转到另一个网站(显然不需要添加)

x86 segmentation-fault nasm game-development
1个回答
0
投票

正如哈罗德在评论中所说,你必须退出该程序。

如果您使用的是 Linux:

如果您的代码是 x86:

mov eax, 1   ; SYS_EXIT
xor ebx, ebx ; exit code = 0
int 80h

如果x86-64:

mov rax, 60
xor rdi, rdi
syscall

如果您使用的是 Windows:

如果是x86:
您必须将

extern _ExitProcess@4
添加到您的代码中,然后:

push dword 0 ; exit code
call _ExitProcess@4

如果是 x86-64: 添加

extern ExitProcess
,然后

mov rcx, 0 ; Exit code (on x64 windows, the first parameter is in rcx)
call ExitProcess

如果您使用的是 Windows,则必须将您的程序链接到
kernel32.lib

© www.soinside.com 2019 - 2024. All rights reserved.