首页 > 解决方案 > 3d C 阵列组装

问题描述

我在视频缓冲区中一起渲染 10x12 像素图

buffer[20][512] = malloc(10*12)

我在 20 个组中有多达 512 个潜在的 10x12 位图。我只使用一个组号:0 buffer[group][number of 10x12 tiles]

因此,buffer[0][mapindex]

每次调用该函数时,我只需要索引不同的地图。我将缓冲区传递给 nasm 函数tile_render(buffer,0,mapindex);

这是我迷路的地方:

    lea esi,[ebp + 12]; Passing the buffer from the stack

    mov eax,[ebp + 36]   ;Location of mapindex on the stack

    I am looping through 10 x 12 trying to render the pixels

    mov dl,[4*esi + eax +8] 

    move byte [edi + ebx],dl  ;moving one byte at a time.

    //code omitted

    add ebx,320  

但是,我没有找到 10x12 像素的正确地址,这意味着我只是在屏幕上出现乱码。

当然还有其他方法可以处理这个问题,我可以做得很好,但我想知道如何在汇编中更好地使用 3 维数组。在这方面,我的经验是新手,所以我希望有人以前处理过这种情况。

标签: c++carrays

解决方案


找到了这个案例的解决方案:

mov esi,[ebp + 12] ; buffer[20][512] = malloc(10*12)
mov edx,[esi]    ;Move to first bitmap
lea esi,[edx]    ;first bitmap address
mov eax,[ebx + 36] ;index to each map
mov ecx,120        ;120 = 12x10 size bit map
mul ecx            ;120 x map index.
mov dl. [esi + eax] ;index through to the output buffer
mov [edi + ebx],dl   ; next
.
.
.
add ebx,320

推荐阅读