Compile and count the number of uppercase and lowercase letters, numbers, and other characters in a string (full debug implementation)

The purpose of writing this blog is because of the experiment report required by a certain assembly teacher; there are many examples of assembly code to write statistics on the number of characters in a string on the Internet, but we require to write with the -A command under debug, which is a bit Cheating~

Because it is written with the debug command, there are no variables or code segments, so it is stipulated that:
use the segment register to store the number of characters:
ds[100] store the string
ds[200] store the number of lowercase letters
ds[210] store
Number of uppercase letters ds[220] Store numbers
ds[230] Store other characters
Note: You can specify the address for storage; the
first step:
Use the -e command to store a string into ds[100], you can use the -d command to view Storage situation: (the right side is a string, the left is the 16-bit ASCII code of the corresponding character)
Insert picture description here
Step 2:
First look at the code logic:

mov cx,15      ;循环15次(loop指令所需)
mov si,100     ;存储字符串首地址
lop:
mov al,[si]    ;将ds[si]字符的ASCII码给al(即字符串第一个字符)
cmp al,61      ;与'a'比较(这里需用字符对应ASCII码)
jb b1          ;如果小于’a’跳转到b1
cmp al,7A   
ja b1          ;如果大于’z’跳转b1
inc ds[200]    ;不跳转(即在a-z之间)小写字母+1
jmp b4
b1:
cmp al,41  
jb b2          ;如果小于’A’跳转b2
cmp al,5A
ja b2          ;如果大于’Z’跳转b2
inc ds[210]    ;大写字母+1
jmp b4
b2:
cmp al,30
jb b3          ;如果小于’0’跳转b3
cmp al,39
ja b3          ;如果大于’9’跳转b3
inc ds[220]    ;数字+1
jmp b4
b3:
inc ds[230]    ;其它字符+1
b4:
inc si         ;取下一个字符
loop lop       ;循环

Note: The overall logic: Take out a character and compare it with lowercase letters, uppercase letters, and numbers in sequence; the ones in between correspond to the character ++, and jump out. If not, continue down, and the remaining characters are other characters. (Code logic is not optimal, personal ability is limited)

Of course, there is a slight difference under debug:
Insert picture description here
Note: Because there is no lop, b1, b2... code segment mark under debug, you can only jmp to the corresponding code segment address. The starting address of the code is 0100, if the jmp address is different, it needs to be changed accordingly.
The third step:
Run the code with -g=0100 0139, and
-d ds:200 to see the running result (I don't want to edit it again, so I won't do the demonstration).

个人原创,能力有限,如有错误,欢迎指正~

Guess you like

Origin blog.csdn.net/z18223345669/article/details/109341149