Yasm编译x86_64 Intel语法汇编遇rbp错误,求替代BITS 64的命令行参数
Hey there, let's break down what's happening and fix that error without touching your source code.
Why You're Seeing This Error
The error pops up because Yasm is defaulting to 32-bit x86 mode when parsing your code. In 32-bit mode, rbp isn't a recognized built-in register (the 32-bit equivalent is ebp), so Yasm treats rbp like an undefined variable/symbol instead of a register. Even though you added -m amd64 to target 64-bit architecture, Yasm still needs an explicit nudge to parse the code itself in 64-bit mode.
Fixes via Command Line (No Source Changes Needed)
You have two straightforward options to force Yasm into 64-bit parsing mode:
Specify a 64-bit Output Format
Yasm will automatically switch to 64-bit parsing if you tell it to output a 64-bit binary format. Use-f elf64for Linux/macOS ELF binaries, or-f win64for Windows PE binaries. Your command becomes:yasm foo.asm -a x86 -m amd64 -f elf64Force 64-bit Parsing Directly
If you don't want to lock into a specific output format, use Yasm's--force-bits 64flag to explicitly set the parsing mode to 64-bit. Here's the command:yasm foo.asm -a x86 -m amd64 --force-bits 64
Quick Note on the BITS 64 Pseudoinstruction
Just to clarify what that pseudoinstruction does: BITS 64 tells the assembler "treat all subsequent code as 64-bit x86". This switches the register set (enables 64-bit registers like rbp, rax), adjusts instruction encoding rules, and sets address length to 64 bits. The command line flags above do exactly this same thing globally, so you don't need to add the line to your source.
内容的提问来源于stack exchange,提问作者Siler

