定义一个包含10个16位字的数组。读取包含键盘中任何字符的字符串的值。之后,字符串应该被转换,因此它应该只保留小写字母的元素(a
- z
)。
然后,在屏幕上打印出字符串,并在寄存器CX
中存储修改序列的元素数。
这是我的代码:
data segment
array dw 10 dup (?)
i db ?
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
mov i, 0d
mov bx, 0h
insert: ;inserting elements in array work only for db, but i need to work for dw
mov ah, 01h
int 21h
mov array [bx], al
inc bx
inc i
cmp i,4d
JNE insert
mov bx, 0h
mov cl, i
go: ; loop for finding numbers or same character who are not lowercase letters, deleting,
; and moving lowercase letters on their positions
mov ax, array[bx]
cmp ax, 97d
jl notchar
cmp ax, 97d
jg notchar
loop go
mov ax, 4c00h
int 21h
ends
end start
我的问题是,它与dw
无法正常工作。有人能帮助我吗?
答案 0 :(得分:2)
没有任何东西可以阻止在数组中存储一个字而不是一个字节。
insert: ;inserting elements in array work only for db, but i need to work for dw
mov ah, 01h
int 21h
mov ah, 0 ;ADD THIS LINE
mov array [bx], ax ;CHANGE AL TO AX
add bx, 2 ;ADD 2 BECAUSE THE ARRAY CONSIST OF WORDS
inc i
cmp i, 4
JNE insert
程序的第二部分需要进行一些修改:
mov ax, array[bx] ;USE ONLY AL, AH=0
cmp al, 97 ;ASCII FOR 'a'
jb notchar ;USE UNSIGNED COMPARISON, SO USE 'JB'
cmp al, 97+25 ;ASCII FOR 'z'
ja notchar ;USE UNSIGNED COMPARISON, SO USE 'JA'