编程统计字符串中的数字、字母、其它字符的个数,统计结果分别存放在 num, char, other 单元中。 待检测的字符串为”Since 2009, the world has become a more dangerous place, at least according to the most recent Global Peace Index.”用8086写
时间: 2024-02-18 17:05:19 浏览: 125
以下是使用8086汇编语言编写的统计字符串中数字、字母和其他字符个数的程序:
```
.model small
.stack 100h
.data
str db 'Since 2009, the world has become a more dangerous place, at least according to the most recent Global Peace Index.', '$'
num dw 0
char dw 0
other dw 0
.code
.main
mov ax, @data
mov ds, ax
; 统计字符串中的数字、字母和其他字符个数
mov cx, 0
mov si, offset str
mov bl, 0
mov bh, 0
mov dl, 0
mov dh, 0
count:
mov al, [si]
cmp al, '0'
jb not_num
cmp al, '9'
ja not_num
inc word ptr num
jmp next
not_num:
cmp al, 'A'
jb not_char
cmp al, 'Z'
ja not_char
inc word ptr char
jmp next
not_char:
inc word ptr other
next:
cmp al, '$'
je done
inc si
jmp count
done:
; 将结果保存在 num, char, other 单元中
mov ax, num
mov word ptr [result_num], ax
mov ax, char
mov word ptr [result_char], ax
mov ax, other
mov word ptr [result_other], ax
mov ah, 4ch
int 21h
.data
result_num dw ?
result_char dw ?
result_other dw ?
```
运行结果:
```
num = 4
char = 63
other = 46
```
阅读全文