string - 用汇编语言将字符存储在内存位置
问题描述
我正在尝试用汇编语言编写一个程序,它将用 'U' 替换字符串 STRVAR 中的所有字母 'T' 并将新字符串放在 OUTPUT 中。我认为我应该在整个循环过程中将每个字符一个接一个地存储在 OUTPUT 中,尽管在对 mov 进行了几次试验和错误之后,我已经没有关于如何将字符存储在新内存位置的想法。
STRVAR db "ACGTACGTCCCTTT",0
OUTPUT times 21 db 0
section .text
global CMAIN
CMAIN:
;write your code here
lea esi, [STRVAR]
L1:
mov al, [esi]
cmp al, 0
JE FINISH
cmp al, 'T'
JE REPLACE
JNE CONTINUE
inc esi
jmp L1
REPLACE:
;store character here
inc esi
jmp L1
CONTINUE:
;store character here
inc esi
jmp L1
FINISH:
xor eax, eax
ret
解决方案
我遵循了 Jester 分享的信息,最终让程序根据规范中的说明工作。我意识到我需要添加section .data
并引入另一个点,在这种情况下,lea edi, [OUTPUT]
存储每个字符并使用它来打印一个新字符串。
%include "io.inc"
section .data
STRVAR db "ACGTACGTCCCTTT",0
OUTPUT times 21 db 0
section .text
global CMAIN
CMAIN:
;write your code here
lea esi, [STRVAR]
lea edi, [OUTPUT]
L1:
mov al, [esi]
cmp al, 0
JE FINISH
cmp al, 'T'
JE REPLACE
JNE CONTINUE
inc esi
inc edi
jmp L1
REPLACE:
mov byte[edi], 'U'
inc esi
inc edi
jmp L1
CONTINUE:
mov byte[edi], al
inc esi
inc edi
jmp L1
FINISH:
mov byte [edi], 0
PRINT_STRING OUTPUT
PRINT_DEC 1, [edi] ;check if the terminating 0 is also included
xor eax, eax
ret
推荐阅读
- excel-formula - 我需要在公式输出范围内自动计算 UNIQUE 值,该范围可能为空白,也可能不为空白
- r - 如何在数据帧列表(或子集数据帧)上循环地理映射函数
- node.js - 使用 node.js 从 2 个 postgres 表中查询所有数据
- javascript - Javascript如何访问用jQuery加载的HTML文件中的元素
- xamarin - Xamarin.UITest 中的 Environment.System.Environment.SpecialFolder.MyDocuments 与应用程序中的不同
- json - 在 ASP.NET 中工作的 JSON 查询在 ASP.NET-Core 3.0 中无法将字段查询从数据库重新调整到用户表单
- tensorflow - Tensorflow:找出预构建的 tensorflow 轮子所针对的 CUDA/CuDNN 版本
- php - Yii 1.1:读取用于识别用户的 $_COOKIE 时的竞争条件
- python - 为什么 xlwings.App(visible = False) 在我的代码中不起作用?
- c++ - 如何使用距离公式用纯色填充我的圆圈?