【发布时间】:2015-01-07 17:07:34
【问题描述】:
你能告诉我如何在 MASM 中访问两个维度数组吗?
C++ 代码:
int k = 0
for (i = 0; i<5; ++i)
{
if (k == text.length())break;
for (j = 0; j<2; ++j)
{
for (t = 0; t<26; ++t)
{
if (text[k] == letters[t]){ tab[i][j] = t; k++; break; }
}
}
}
MASM
mov al, [ebx] ;ebx - begin of text array
xor esi, esi
for1:
cmp al, 00
je break_for1
mov j, 0
for2:
mov t, 0
mov ecx, adrAlphabet ;ecx - begin of letters array
for3:
;if (text[k] == letters[t]){ tab[i][j] = t; k++; break; }
mov ah, [ecx]
cmp ah, 00
je end_of_alphabet
cmp al, 00
je end_of_text
cmp al, ah
jne not_equal
;here comes the problem
mov edx, t
mov [letters + (esi*4 + j)*4], edx
;
inc k
inc ebx
jmp break_t
; end if
not_equal:
inc ecx
inc t
cmp t, 26
jne for3
break_t:
inc j
cmp j, 2
jne for2
inc esi
cmp esi, 5
jne for1
break_for1:
end
这只是我的代码的一部分,但我只想了解数组。 你能举一些例子我如何在 MASM 中使用 tab[i][j] 吗? 另一个问题是,如何修改 tab 数组的长度?简而言之:在程序开始时会计算 tab 大小,然后我想设置数组大小。
谢谢
【问题讨论】:
-
1) 将
i乘以每行的元素数,加上j,再乘以每个元素的大小,最后加上数组的基地址。 2) 为数组动态分配内存。你如何做到这一点取决于你的目标操作系统。如果您正在编写 Windows 应用程序,请查找HeapAlloc。
标签: arrays loops assembly x86 masm