Declaring and defining an array and matrix in assembly?

19,887

Solution 1

I solved this using an example provided by the emulator.

Basically matrixes in assembly are declared the same as regular variables, a 2x2 matrix for example is declared like this:

matrix db ?,?,?,?   ; Obviously `?` can be replaced by any value

or

matrix db dup('?')

Then the user decides where he considers a "row" ends and another starts. For example if we have a variable with bytes 1,2,3,4 the user may consider that 1,2 are one row and 3,4 are another.

This is how you point to an item in the matrix:

mov bx,0
lea si,matrix
mov matriz[si][bx],0   ; [si][bx] holds the value of the first cell

Now if each row holds 2 items, one should just do this to go to the second row:

add bx,2
mov matriz[si][bx],1   ; Now [si][bx] points to cell 0x1

Solution 2

Emu8086 syntax is almost the same as the MASM syntax, so to declare an uninitialized array that will hold 3 bytes:

arr1    db 3 dup (?)
Share:
19,887
lisovaccaro
Author by

lisovaccaro

Updated on August 22, 2022

Comments

  • lisovaccaro
    lisovaccaro over 1 year

    It seems I can't get enough good documentation on assembly, at least none that's intelligible.

    Could someone post a simple example on how to declare an array and a matrix on assembly? And possibly how to modify items in it. It will be of great help for me and probably to many others.