assembly - 如何在字符串定义中将 ASCII 字符大写?

标签 assembly nasm preprocessor capitalize

对于我创建的脚本 for another question ,我必须在字符串定义中将传递给 NASM 的文件名大写。我使用 %substr 在 %rep 循环中提取单个字符,并使用 %strlen 进行重复计数。我尝试了以下方法来将字符大写:

$ cat test.asm
 %define cc 'a'
 %if cc >= 'a' && cc <= 'z'
  %strcat cc cc - 'a' + 'A'
 %endif

但失败如下:

$ nasm test.asm
test.asm:3: error: non-string passed to `%strcat' (9)
$

错误消息是由 NASM 预处理器源中的该位生成的:https://repo.or.cz/nasm.git/blob/437e0ffa01505d173a8b9cfe2decf74f2e9795a5:/asm/preproc.c#l3472

它使用定义在 https://repo.or.cz/nasm.git/blob/437e0ffa01505d173a8b9cfe2decf74f2e9795a5:/asm/preproc.c#l207 中的 token 类型(9 似乎是 TOK_OTHER。)

最佳答案

我最终采用了这种解决问题的方法,尽管看起来很奇怪,可能还有更好的方法。

 %if cc >= 'a' && cc <= 'z'
  %substr cc "ABCDEFGHIJKLMNOPQRSTUVWXYZ" (cc - 'a' + 1)
 %endif

来 self 的来源 https://hg.ulukai.org/ecm/bootimg/file/f8c890f92116f2593c1e2016a71f95dfd7bbcd36/bootimg.asm#l314

关于assembly - 如何在字符串定义中将 ASCII 字符大写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57233566/

相关文章:

在linux中从C代码调用汇编函数

c++ - __cdecl、__stdcall 和 __fastcall 的调用方式完全相同?

assembly - LEA 和其他指令如何运作?

assembly - 从 Assembly x86 NASM 内存中读取 16 位

c++ - 使用clang预处理程序将C++源文件连接为一个

c - 正则表达式谜题 : encapsulated structures

Linux 汇编调试器

c - NASM 32 位 : printing content of register by printf

assembly - 为什么在 NASM 中我们必须使用方括号 ([]) 来 MOV 到内存位置?

fortran - 检查是否定义了内部模块常量