From: Alan Cox Date: Mon, 30 Oct 2017 17:40:58 +0000 (+0000) Subject: ld: add the hash function X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=2b2e492a100e4e0c1fe81b63269c6e3f802667e1;p=FUZIX.git ld: add the hash function --- diff --git a/Applications/MWC/cmd/asz80/ld.c b/Applications/MWC/cmd/asz80/ld.c index 51751b18..0fdc7eab 100644 --- a/Applications/MWC/cmd/asz80/ld.c +++ b/Applications/MWC/cmd/asz80/ld.c @@ -127,8 +127,13 @@ struct symbol *find_symbol(const char *name, int hash) static uint8_t hash_symbol(const char *name) { - /* TODO */ - return 0; + int hash = 0; + uint8_t n = 16; + + do { + hash += *name++; + } while (--n); + return (hash&(NHASH-1)); } /* Check if a symbol name is known but undefined. We use this to decide diff --git a/Applications/MWC/cmd/asz80/ld.h b/Applications/MWC/cmd/asz80/ld.h index 27b2dfc9..b91a9fbc 100644 --- a/Applications/MWC/cmd/asz80/ld.h +++ b/Applications/MWC/cmd/asz80/ld.h @@ -23,5 +23,5 @@ struct object { off_t off; /* For libraries */ }; -#define NHASH 64 +#define NHASH 64 /* Must be a power of 2 */