程序集:使用减去 2 个字符文字的“.equ”出现无效操作数错误
assembly: Invalid operands error using ".equ" with a subtraction of 2 character literals
当我尝试 assemble 我的代码时出现以下 assembler 错误:
Error: invalid operands (*UND* and *UND* sections) for `-' when setting `UPPER_CONVERSION'
我正在使用以下命令 assemble:
as -32 toupper.s -o toupper.o
我的代码(我指的是this书中的从低到高的转换代码):
.section .text
###CONSTANTS##
#The lower boundary of our search
.equ LOWERCASE_A, ’a’
#The upper boundary of our search
.equ LOWERCASE_Z, ’z’
#Conversion between upper and lower case
.equ UPPER_CONVERSION, ’A’ - ’a’ ## error on this line
请参阅此问题的第一个版本以获取使用 $UPPER_CONVERSION
作为立即数的完整代码。但是上面是一个产生 assembler 错误消息的 MCVE,因此不能用作定义 UPPER_CONVERSION = 65 - 97 = -32
的方法
我看到了this问题,我尝试了解决方案,但我认为它没有关系(我这里可能是错的)。
您的源代码中有一些非 ASCII 引号字符:
在 GNU/Linux 上将您的 ’A’ - ’a’
粘贴到 hd
(又名 hexdump -C
)显示:
00000000 e2 80 99 41 e2 80 99 20 2d 20 e2 80 99 61 e2 80 |...A... - ...a..|
00000010 99 0a |..|
所以问题是你的引号是 3 字节的 UTF-8 序列,而不是 ASCII 单引号。
重新输入为
.equ UPPER_CONVERSION, 'A' - 'a'
生成一个可以很好地组装的文件。 (只包含那一行。我没有尝试你的整个文件。)
当我尝试 assemble 我的代码时出现以下 assembler 错误:
Error: invalid operands (*UND* and *UND* sections) for `-' when setting `UPPER_CONVERSION'
我正在使用以下命令 assemble:
as -32 toupper.s -o toupper.o
我的代码(我指的是this书中的从低到高的转换代码):
.section .text ###CONSTANTS## #The lower boundary of our search .equ LOWERCASE_A, ’a’ #The upper boundary of our search .equ LOWERCASE_Z, ’z’ #Conversion between upper and lower case .equ UPPER_CONVERSION, ’A’ - ’a’ ## error on this line
请参阅此问题的第一个版本以获取使用 $UPPER_CONVERSION
作为立即数的完整代码。但是上面是一个产生 assembler 错误消息的 MCVE,因此不能用作定义 UPPER_CONVERSION = 65 - 97 = -32
我看到了this问题,我尝试了解决方案,但我认为它没有关系(我这里可能是错的)。
您的源代码中有一些非 ASCII 引号字符:
在 GNU/Linux 上将您的 ’A’ - ’a’
粘贴到 hd
(又名 hexdump -C
)显示:
00000000 e2 80 99 41 e2 80 99 20 2d 20 e2 80 99 61 e2 80 |...A... - ...a..|
00000010 99 0a |..|
所以问题是你的引号是 3 字节的 UTF-8 序列,而不是 ASCII 单引号。
重新输入为
.equ UPPER_CONVERSION, 'A' - 'a'
生成一个可以很好地组装的文件。 (只包含那一行。我没有尝试你的整个文件。)