我正在编写汇编代码,提示用户输入一串小写字符,然后输出包含所有大写字符的相同字符串。我的想法是迭代从特定地址开始的字节,并从每个字节中减去 20H(将小写变为大写),直到到达具有特定值的字节。我对 Assembly 相当缺乏经验,所以我不确定这样的循环的语法是什么样的。
谁能提供一些示例代码或指导我在哪里可以找到此类语法的示例?
任何帮助是极大的赞赏!
通常,字符串以 null(十六进制的 0x00)结尾。假设这就是您选择执行的操作,下面是一些示例代码。我不确定您使用的是哪种汇编器,甚至不确定哪种语法,但是这个 x86 代码应该在 MASM 中工作:
mov cl, 0 ; cl is the counter register, set it to
; zero (the first character in the string)
start: ; Beginning of loop
mov al, bytes[cl] ; Read the next byte from memory
cmp al, 0 ; Compare the byte to null (the terminator)
je end ; If the byte is null, jump out of the loop
sub al, 20h ; Convert to upper case
; A better solution would be: and al, 0DFh
; Output the character in al
add cl, 1 ; Move to the next byte in the string
jmp start ; Loop
end:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)