我正在编写汇编代码,提示用户输入一些小写字符,然后输出带有所有UPPER-CASE字符的相同字符串.我的想法是迭代从特定地址开始的字节,并从每个字节中减去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:
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8635 次 |
| 最近记录: |