使用数组汇编程序 8086
Working with arrays assembler 8086
定义一个包含十个 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
一起正常工作。有人可以帮助我吗?
没有什么能阻止您在数组中存储单词而不是字节。
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'
定义一个包含十个 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
一起正常工作。有人可以帮助我吗?
没有什么能阻止您在数组中存储单词而不是字节。
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'