Declaring and defining an array and matrix in an assembly?

It seems that I can not get enough good documentation on the assembly, at least no one understands this.

Can someone post a simple example of how to declare an array and matrix on an assembly? And perhaps how to change the elements in it. It will be very useful for me and probably for many others.

+4
source share
2 answers

I solved this using the example provided by the emulator.

Basically, matrices in an assembly are declared the same as regular variables, for example, a 2x2 matrix is โ€‹โ€‹declared as follows:

matrix db ?,?,?,? ; Obviously `?` can be replaced by any value or matrix db dup('?') 

The user then decides where he believes the โ€œlineโ€ ends and the other begins. For example, if we have a variable with bytes 1,2,3,4, the user can assume that 1,2 is one row and 3.4 is another.

Here's how you point to an element in a matrix:

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

Now, if each line contains 2 elements, you just need to do this to go to the second line:

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

The syntax of Emu8086 is almost the same as the MASM syntax, so declare an uninitialized array that will contain 3 bytes:

 arr1 db 3 dup (?) 
+3
source

Source: https://habr.com/ru/post/1487181/


All Articles