我不明白如何遍历数组
I don't understand how to walk through the array
我想使用 si 寄存器遍历 duration 数字数组。但它不适合我。如果我只传递一个数字 dur,那么它工作正常,如果我想迭代,那么它会冻结,没有别的。解释错误。谢谢!
sseg segment stack
db 256 dup(?)
sseg ends
dseg segment
music dw 4063, 2559, 3835
duration dd 270000, 360000, 180000
dur dd 270000
len dw 3
dseg ends
cseg segment
assume ss:sseg,cs:cseg,ds:dseg
start: jmp main
main: push ds
xor ax,ax
push ax
mov ax,dseg
mov ds,ax
cli
;------------------------------
xor di,di
xor si,si
cycle:
mov al,10110110b
out 43h,al
in al,61h
or al,3
out 61h,al
;------------
mov ax,music[si]
out 42h,al
mov al,ah
out 42h,al
les dx,dur ;duratin[si]
mov cx,es
mov ah,86h
int 15h
;------------
in al,61h
and al,11111100b
out 61h,al
;------------
inc si
inc di
cmp si,len
jnae cycle
;------------------------------
exit:
sti
mov ax,4c00h
int 21h
cseg ends
end start
mov ax,music[si]
MASM 是否允许 music[si]
或 [music+si]
在接下来的讨论中并不重要。
重要的一点是 SI
寄存器不是我们从高级语言中知道的数组索引,而是 它是从数组开始的偏移量并且总是以字节为单位.
因此,在您的程序中,您需要将 2 添加到寻址 music 数组(单词)的寄存器中,并且您需要将 4 添加到寻址 duration[ 的寄存器中=25=]数组(双字).
music dw 4063, 2559, 3835
duration dd 270000, 360000, 180000
len = $-offset duration
...
xor di, di ; Offset in duration array
xor si, si ; Offset in music array
cycle:
...
mov ax, music[si]
...
les dx, duration[di] ; This is DI, beware of your typo
mov cx, es
mov ah, 86h
int 15h
...
add si, 2 ; To next music item (word=2)
add di, 4 ; To next duration item (dword=4)
cmp di, len
jb cycle
我想使用 si 寄存器遍历 duration 数字数组。但它不适合我。如果我只传递一个数字 dur,那么它工作正常,如果我想迭代,那么它会冻结,没有别的。解释错误。谢谢!
sseg segment stack
db 256 dup(?)
sseg ends
dseg segment
music dw 4063, 2559, 3835
duration dd 270000, 360000, 180000
dur dd 270000
len dw 3
dseg ends
cseg segment
assume ss:sseg,cs:cseg,ds:dseg
start: jmp main
main: push ds
xor ax,ax
push ax
mov ax,dseg
mov ds,ax
cli
;------------------------------
xor di,di
xor si,si
cycle:
mov al,10110110b
out 43h,al
in al,61h
or al,3
out 61h,al
;------------
mov ax,music[si]
out 42h,al
mov al,ah
out 42h,al
les dx,dur ;duratin[si]
mov cx,es
mov ah,86h
int 15h
;------------
in al,61h
and al,11111100b
out 61h,al
;------------
inc si
inc di
cmp si,len
jnae cycle
;------------------------------
exit:
sti
mov ax,4c00h
int 21h
cseg ends
end start
mov ax,music[si]
MASM 是否允许 music[si]
或 [music+si]
在接下来的讨论中并不重要。
重要的一点是 SI
寄存器不是我们从高级语言中知道的数组索引,而是 它是从数组开始的偏移量并且总是以字节为单位.
因此,在您的程序中,您需要将 2 添加到寻址 music 数组(单词)的寄存器中,并且您需要将 4 添加到寻址 duration[ 的寄存器中=25=]数组(双字).
music dw 4063, 2559, 3835
duration dd 270000, 360000, 180000
len = $-offset duration
...
xor di, di ; Offset in duration array
xor si, si ; Offset in music array
cycle:
...
mov ax, music[si]
...
les dx, duration[di] ; This is DI, beware of your typo
mov cx, es
mov ah, 86h
int 15h
...
add si, 2 ; To next music item (word=2)
add di, 4 ; To next duration item (dword=4)
cmp di, len
jb cycle