我如何从用户获取字符串输入并仅使用汇编语言将字母和奇数更改为大写

时间:2015-01-25 09:23:01

标签: assembly

我如何从用户获取字符串输入并将字母仅更改为大写字母,并且必须更改汇编语言中字符串中唯一的奇数位?例如用户输入yasmine12输出必须是YaSmInE12

1 个答案:

答案 0 :(得分:0)

这是转换字符串的代码。但我不能告诉你如何读取和输出字符串,因为这取决于你正在使用的操作系统。

jmp start
text db "yasmine12",0  ;a null-terminated string
start: 
lea si, text
lea di, text
loop_block:
lodsb
or al, al 
jz end      ;jump to the end of the program, if the null-byte at the end of the string is reached
mov ah, al
cmp ah, "a"
jb omit
cmp ah, "z" ;test whether the letter is a lowercase
ja omit
shr ah, 1  ;test whether the letter is odd
jnc omit
sub al, 32 ;convert lowercase to uppercase
omit:      ;label to which the program springs if the char shouldn't be converted
stosb      ;overwrite the old char with the new char
jmp loop_block  
end:
;put the code here to output the string and end the program