汇编语言8086 [英] Assembly language 8086

查看:205
本文介绍了汇编语言8086的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照大会8086个问题,我不知道如何使用二维数组。当我为使用这样
MOV AR [CX] [DX] 我得到一个错误,当我想我们​​ SI DI 在数组也返回一个错误。

I've a problem with Assembly 8086. I don't know how to use an 2D array. When I m using like this mov ar[cx][dx] I get an error, and when I want to us SIand DI in an array it also returns an error.

推荐答案

我是在它的汇编语言提供数组查找语义的CPU中pssed很IM $ P $。或者说,我会生气,如果这意味着更重要的东西已经牺牲了。

I would be very impressed in a CPU that provided array lookup semantics in its assembly language. Or rather, I would be annoyed if it meant something more important had been sacrificed.

做数组查找在大会一般性方法是做计算自己打开这两个指标的二维数组到一个单一的指数为一维数组,并调整为元素的大小。例如(伪code):

The general way to do array lookup in assembly is by doing the calculation yourself to turn the two indexes for a 2D array into a single index for a 1D array, and adjust for the element size. For example (pseudo-code):

ax = cx * major_dimension
ax = ax + dx
ax = ax * element_size
ax = peek[base+ax]

其中, major_dimension 是二维数组的尺寸(其中标注使用完全取决于数据是如何在内存布局), element_size 是每个元素的大小,是数组的开始和CX / DX是你使用访问索引数组。

where major_dimension is one of the dimensions of the 2D array (which dimension you use depends entirely on how the data is laid out in memory), element_size is the size of each element, base is the start of the array and cx/dx are the indexes you're using to access the array.

例如,如果你有一个3×4( A [0-2] [0-3] )阵列内存位置 0x0700 ,这些都是32位整数:

For example, if you have a 3-by-4 (a[0-2][0-3]) array at memory location 0x0700 and these are 32-bit integers:

        +--------+--------+--------+--------+
0x0700: | a[0,0] | a[0,1] | a[0,2] | a[0,3] |
        +--------+--------+--------+--------+
0x0710: | a[1,0] | a[1,1] | a[1,2] | a[1,3] |
        +--------+--------+--------+--------+
0x0720: | a[2,0] | a[2,1] | a[2,2] | a[2,3] |
        +--------+--------+--------+--------+

要找到数组 A [N,M] ,你计算的主要指标乘以四加次要指标,扩展到正确的单元尺寸(4字节),然后加入基地。为了找到元素 A [2,1]

To find array element a[n,m], you calculate the major index multiplied by four plus the minor index, scale it to the correct element size (4 bytes) then add the base. To find element a[2,1]

addr = base   + (n * 4 + m) * 4
     = 0x0700 + (2 * 4 + 1) * 4
     = 0x0700 + (8     + 1) * 4
     = 0x0700 + (9        ) * 4
     = 0x0700 + 36
     = 0x0700 + 0x24
     = 0x0724

那么这就是你使用的仰视一维数组的地址。

Then that's the address you use for looking up the 1D array.

和,基于所述评论是:

ar   db   3dup(3dup(0))
     mov  ar[bx][si],al

会的工作,这是不完全正确( AR [BX] [SI] 是特定MASM语法等同于 AR [BX + SI] )。

would work, that's not quite right (ar[bx][si] is masm-specific syntax equivalent to ar[bx+si]).

所有这一切确实是一个简单的加法与 BX AR 地址SI 寄存器。它的的缩放 BX SI 注册考虑到的主要尺寸,它的的缩放 BX + SI 的元素大小值。因此,它只会工作,用于开发的二维数组的字节的,其中主要尺寸为1,我是pretty肯定将使它一维数组: - )

All that does is a simple addition of the ar address with the bx and si registers. It does not scale the bx or si register to take into account the major dimension and it does not scale the bx+si value for the element size. So it will only work as-is for a 2D array of bytes where the major dimension is 1, which I'm pretty sure would make it a 1D array :-)

要为任何情况下工作,你首先需要乘以 BX SI (取决于正在由主要维度用于大尺寸),那么这两个 BX SI 的元素大小。

To work for any case, you would first need to multiply bx or si (depending on which is being used for the major dimension) by the major dimension then both bx and si by the element size.

这篇关于汇编语言8086的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆