好的,为了使事情尽可能简单,说我有一个基本的循环,我想用来修改标记为a的数组的一些元素。在下面的示例代码中,我尝试用1替换1的所有元素,但这并不起作用。8086程序集 - 如何访问循环内的数组元素
assume cs:code ,ds:data
data segment
a db 1,2,3,4
i db 0
data ends
code segment
start:
mov ax,data
mov ds,ax
lea si,a
the_loop:
mov cl,i
cmp cl,4
jae the_end
mov ds:si[i],1 ; this is the part that i don't really understand since
inc i ; i'm expecting i=0 and ds:si[i] equiv to ds:si[0] which
loop the_loop ; is apparently not the case here since i actually receives the
; the value 1
the_end:
mov ax,4c00h
int 21h
code ends
end start
我知道我可以简单地通过修改存储在al
的lodsb
指令之后的元素做到这一点,只是存储。但我想知道是否有可能做到像我上面尝试过的那样。
'mov bx,[i]'如果'i'是一个字节就不会组装或工作正常。你用'movzx'弄明白了。但知道这是80386+指令可能很重要。 – 2013-02-20 13:09:31
@AlexeyFrunze你是对的,所以我修复它并转换为8088/8086代码。 – nrz 2013-02-20 13:12:00