there is a c code
I want to translate it to asm.here is what i do
But how can not using
to init it?just like the c!
Thanks guys
int table[5][6] ={{1,0,0,1,0,0,},
{0,1,0,0,1,1},
{1,0,0,1,0,0},
{0,1,1,0,1,1},
{1,0,0,1,0,0}};
I want to translate it to asm.here is what i do
item6 struct
firstdword dword ?
seconddword dword ?
thirddword dword ?
fourthdword dword ?
fifthdword dword ?
sixthdword dword ?
item6 ends
myarray item6 5 dup (<0,0,0,0,0,0>)
But how can not using
mov myarray[0*sizeof item6].firstdword,1
to init it?just like the c!
Thanks guys
The array seems to be initialized in the "data" section of the C code. After defining your item6 struct, you could do it as follows in asm in the .data section.
Raymond
.data
table1 item6 <1,0,0,1,0,0>
table2 item6 <0,1,0,0,1,1>
etc...
Raymond
thanks! Look at my code am i right?or there is a better way?
item6 struct
firstdword dword ?
seconddword dword ?
thirddword dword ?
fourthdword dword ?
fifthdword dword ?
sixthdword dword ?
item6 ends
myarray struct
table1 item6 <1,0,0,1,0,0>
table2 item6 <0,1,0,0,1,1>
table3 item6 <1,0,0,1,0,0>
table4 item6 <0,1,1,0,1,1>
table5 item6 <1,0,0,1,0,0>
myarray ends
Another way, the table could be initialized as
either table or bable and accessed like C
using row and column, I replaced the 0
with x for table[1,2]
either table or bable and accessed like C
using row and column, I replaced the 0
with x for table[1,2]
.data
; col
; 0 1 2 3 4 5
table dd 1,0,0,1,0,0 ; row 0 table is 5 rows by 6 columns
dd 0,1,x,0,1,1 ; row 1
dd 1,0,0,1,0,0 ; row 2
dd 0,1,1,0,1,1 ; row 3
dd 1,0,0,1,0,0 ; row 4
bable dd 1,0,0,1,0,0,\
0,1,x,0,1,1,\
1,0,0,1,0,0,\
0,1,1,0,1,1,\
1,0,0,1,0,0
row dd 1
col dd 2
.code
start:
mov edx, row ; 0..4 5 rows
lea edx,
lea edx, ; edx * 6*4 6*4 == 8*3 == 24 bytes
mov ecx, col ; 0..5 6 columns
mov , 1 ; mov row*6+col,1 aka mov row*24+col*4, 1
There is no real need to initialize the data as part of a structure, it can be simple dwords and addressed similarly to a structure...
table DD 1,0,0,1,0,0
DD 0,1,0,0,1,1
DD 1,0,0,1,0,0
DD 0,1,1,0,1,1
DD 1,0,0,1,0,0
SIZEOFROW = 24
mov eax,
:O yes!it is better and easier than me.thanks!
thanks! Look at my code am i right?or there is a better way?
item6 struct
firstdword dword ?
seconddword dword ?
thirddword dword ?
fourthdword dword ?
fifthdword dword ?
sixthdword dword ?
item6 ends
myarray struct
table1 item6 <1,0,0,1,0,0>
table2 item6 <0,1,0,0,1,1>
table3 item6 <1,0,0,1,0,0>
table4 item6 <0,1,1,0,1,1>
table5 item6 <1,0,0,1,0,0>
myarray ends
Actually, what I think Raymond was going at was creating a list of structures which would make accessing the elements easier in your case. For example.
item6 struct
first dword ?
second dword ?
third dword ?
fourth dword ?
fifth dword ?
sixth dword ?
item6 ends
.data
table0 item6 <1,0,0,1,0,0>
table1 item6 <0,1,0,0,1,1>
table2 item6 <1,0,0,1,0,0>
table3 item6 <0,1,1,0,1,1>
table4 item6 <1,0,0,1,0,0>
...
mov eax, table0.first
mov ebx, table1.second
mov edx, table2.third
etc.
The number after the word table identifies the row and the element of the structure identifies the column. For example, the C version table[1][3] is equivalent to table1.third. This makes for a good bit of typing, but it's definitely one the most readable methods for doing fixed width matrices. Now if you don't know how many columns you are going to have you can't do this, you'll have to use donkey's method and the SIZEOFROW value will be dynamic.. but I wouldn't worry much about that as most matrices are fixed width. (With the exception of lists of strings of course.)
Just thought I would add a little clarification while I was passing through.
Regards,
Bryant Keller