Author Topic: Multi-array struct in assembly  (Read 11435 times)

Offline mik3ca

  • Jr. Member
  • *
  • Posts: 30
Multi-array struct in assembly
« on: February 27, 2021, 02:16:35 AM »
I'm doing a project which requires me to manage a multi-dimensional struct. Each struct is 2 dwords. I'll give an example of what I mean in a real world scenario.

Suppose 10 mailmen are assigned to deliver 10 items to homes on different routes but the only information they have is a street code and a delivery code with a barcode that they scan to find the right house.

So this struct applies for every mailman possible.

Code: [Select]
delivercode dd 0
streetcode dd 0

now for 1 mailman to do 10 items, I could change my declarations to this:

Code: [Select]
delivercode times 10 dd 0
streetcode times 10 dd 0

then I'd have to access them like this (assuming BX=item number wanted and ECX is resulting street code based on that item number):

Code: [Select]
shl BX,2
mov ECX,[streetcode+BX]

But now I'm stuck on the most efficient way to do declarations for the remaining mailmen because I only covered one in this example.

Here is how I would address multiple mailmen:

Assuming BX is house number, and AX is mailman number, I could read values like this maybe:

Code: [Select]
mul AX,200
shl BX,2
add BX,AX
mov ECX,[streetcode+BX]

Is there an easier way to define a multidimensional struct?
like maybe something like:

Code: [Select]
    (delivercode dd 0, streetcode dd 0) times 10 times 10


I have nasm 2.10.04.