Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 程序集x86使用循环将值放入数组_Arrays_Loops_Assembly_X86 - Fatal编程技术网

Arrays 程序集x86使用循环将值放入数组

Arrays 程序集x86使用循环将值放入数组,arrays,loops,assembly,x86,Arrays,Loops,Assembly,X86,我想把数字放在一个长度为10的数组中,但每个数字都比最后一个数字大1。 它的意思是:myArray=0,1,2,3,4,5,6,7,8,9 我试过这个: 理想的 型号小 堆栈100小时 数据集 阵列db 10重复(0) 索引db1 代码段 开始: mov ax,@DATA mov-ds,ax 循环数组: 动产[指数] 添加[intArray+索引],al;这就是问题所在 公司[索引] cmp[index],11 jb loopArray 退出: 移动轴,4c00h int 21h 结束-开始 但

我想把数字放在一个长度为10的数组中,但每个数字都比最后一个数字大1。 它的意思是:
myArray=0,1,2,3,4,5,6,7,8,9

我试过这个:

理想的
型号小
堆栈100小时

数据集

阵列db 10重复(0)
索引db1

代码段

开始:
mov ax,@DATA
mov-ds,ax
循环数组:
动产[指数]
添加[intArray+索引],al;这就是问题所在
公司[索引]
cmp[index],11
jb loopArray
退出:
移动轴,4c00h
int 21h
结束-开始

但是我无法将索引添加到[intArray+index],所以我尝试将其添加到[intArray+al],但这也不起作用

如何每次将索引添加到下一个数组的值

myArray=0,1,2,3,4,5,6,7,8,9

这些是您希望数组包含的数字。但是,由于您将索引变量(将用于索引和存储)初始化为1(使用
索引db 1
),这将导致另一个结果。
只需使用以下内容设置索引:

index db 0
这样设置还有另一个原因! 在符号
[intArray+index]
中,
索引
部分是数组中的一个偏移量。偏移始终是基于零的量。按照您编写程序的方式,它将在数组后面写入第10个值

添加[intArray+索引],al;问题就在这里

你说得对,这就是问题所在。一些汇编器不会编译这个,而其他汇编器只会添加这两个变量的地址。两者都不符合你的目的。您需要的是将索引变量的内容放入寄存器中,并使用该操作数组合

    intArray db 10 dup (0)
    index    db 0
    ...
loopArray:
    movzx    bx, [index]
    mov      [intArray+bx], bl ;Give the BX-th array element the value BL
    inc      [index]
    cmp      [index], 10
    jb       loopArray
使用此代码,索引将从0开始,然后循环将继续,只要索引小于10


当然,你完全可以不用索引变量来编写这个程序

    intArray db 10 dup (0)
    ...
    xor      bx, bx            ;This make the 'index' = 0
loopArray:
    mov      [intArray+bx], bl ;Give the BX-th array element the value BL
    inc      bx
    cmp      bx, 10
    jb       loopArray

假设数组最初是用零填充的,则可以替换:

    mov      [intArray+bx], bl ;Give the BX-th array element the value BL
与:


请记住,只有在数组事先填充了零的情况下,此操作才有效

{add[intArray+al],al}应该有效,为什么不行?它是否编译?为什么要将索引添加到任何内容
MOV
it在那里。您可能需要使用
BX
索引:
mov-bl,[index];loopArray:mov[intArray+bx],bl;inc bl:cmp bl,11:jb loopArray
或类似的循环;mov[intArray+bl],bl;公司(指数),;cmp[指数],11;jb loopArray’它仍然不起作用。是的,它可以编译。谢谢你,我昨天做了这个,这是正确的答案。很高兴帮助你!你好@SepRoland。如何将一个小矩阵改写为一个大矩阵?@SepRoland如果数组是intArray db 10 dup(3 dup(0)),该怎么办?@FereydoonBarikzehy这相当于
intArray db 30 dup(0)
。数组将以30个零元素开始,代码将用0到29之间的数字填充这些元素。
    add      [intArray+bx], bl ;Give the BX-th array element the value BL