flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > Arrays? |
Author |
|
Tomasz Grysztar 15 Mar 2005, 19:52
First of all: in your sample it's enough to write [mystring+0] and [mystring+6] instead of [mystrarray(0)] and [mystrarray(6)], so it's a bit unfortunate example. And generally it should be something like [array_address+size_of_element*index] - this is straightforward assembly way and this is what I personally find less confusing and easy to use, really.
But if you want some HLL-ish syntax, you might try making some macros. For example: Code: macro darray name,type,[value] { common virtual name#.addr type ? name#.itemlen = $-name#.addr name equ name#.addr+name#.itemlen* end virtual forward type value } macro rarray name,type,size { virtual name#.addr type ? name#.itemlen = $-name#.addr name equ name#.addr+name#.itemlen* end virtual if ~ size eq ? repeat size type ? end repeat end if } First one defines an initialized array, second one uninitialized. The only limitation is that you have to declare an array before you use it in code. But the usage is just like you wanted: Code: ; data definition: darray myarray,dd, 10,7,400,98,321 ; data accessing: mov eax,[myarray(3)] ; gets 98 into eax and something like your sample: Code: mystring db 'Hello World!' virtual at mystring rarray mystrarray,db,? end virtual ; data accessing: mov [mystrarray(6)],'U' The only problem can occur, when you want an index from some other variable or register (though in cases of element sizes being powerd of two register will work even with above macros) - then you have to do the address calculations manually - this is assembly, not HLL. |
|||
15 Mar 2005, 19:52 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.