Reputation: 178
I am PHP programmer. For now I need to create simple script in masm where I need to use key => value pairs (ie fast selection value by key - one-to-one). The main idea is that keys can be strings. Is there any analogue of such feature (associative arrays, hash tables etc) in masm? What is the best way to do this correctly? Many thanks!
Upvotes: 1
Views: 1110
Reputation: 95402
@Igor: Welcome to Assembler, where you have to build it yourself on top of the raw iron, or find a linkable library which has implemented this for you.
Most people that drop into assembler have something to do for which they expect there is no existing library (typically, high performance code for a funny task).
But if your assembler code if reasonably sized, you only want to write the high-performance part. Most of the rest of such programs is pretty vanilla stuff (open file, read record),... just you're stuck in assembler.
Here is where Linkage Editors are your friend. Many higher level languages (C, C++, Fortran, Ada, COBOL :) actually compile to native assembler code. This pretty much means that if you can find the routine you want, coded in such a language, you can find a way to call it from your assembler code. The details of that depend on the compiler conventions for the high level language, and on the precise instruction set of the computer. You can pretty much count on the core interface to use a CALL-subroutine machine instruction that the assembler does know about. Finally, you have to explain to your assembler that you want it to link against the compiled code of interest, and learn how to use a link editor to stitch your code to the library you want.
For standard activities like File I/O, etc, invariably there is library made available that offers all the OS capabilities to the assembly language programmer. (How otherwise would there be any higher level programming languages?)
So, what you should do is go fishing for C libraries that implement hash table, and then find out how to invoke them from your assembler.
Or, you can become a good assembly language programmer, and code these things yourself. Depends on whether you want to spend a lot of time learning, or whether you just want to get the job done.
PS: If you don't have something that has to be spectacularly fast, you're probably better off coding in C than coding in assembler. You can still use those libraries :-}
PPS: Considering you are a PHP programmer and use hashes every day because they are available, it may be that your thinking is contaminated by the way you use PHP. Does your computation really need hashes, or will some other data structure work?
Upvotes: 2