[英]Storing a character in a memory location in Assembly Language
我正在嘗試用匯編語言編寫一個程序,它將用'U'替換字符串STRVAR中的所有字母'T',並將新字符串放在OUTPUT中。 我認為我應該在整個循環過程中將每個字符一個接一個地存儲在 OUTPUT 中,盡管在對 mov 進行了多次試驗和錯誤之后,我已經對如何將字符存儲在新的 memory 位置沒有任何想法。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.