News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Lookup tables. Okay, what am i doing wrong.

Started by axtens, May 09, 2007, 08:47:56 AM

Previous topic - Next topic

axtens

G'day

Okay, I have this stuff in an INC file:
;Error Numbers
E_NO_ERROR     EQU 0
E_INVALID_SLOT     EQU 1
E_INVALID_SLOT_SIZE     EQU 2
        E_STORE_NULL            EQU 3
        E_SLOT_NOT_OCCUPIED     EQU 4
        E_SLOT_NOT_INSTANTIATED EQU 5
        E_INSUFFICIENT_MEMORY   EQU 6
        E_FRAMING_ERROR         EQU 7
        E_MID_BAD_BOUNDS        EQU 8
        E_DELETE_BAD_LENGTH EQU 9
        E_DELETE_BAD_POSITION EQU 10
       
MSG_NO_ERROR         DB "No error",0
MSG_INVALID_SLOT         DB "Bad slot number",0
MSG_INVALID_SLOT_SIZE     DB "Bad slot size", 0
MSG_STORE_NULL              DB "Nothing to store",0
MSG_SLOT_NOT_OCCUPIED       DB "Slot not occupied",0
        MSG_SLOT_NOT_INSTANTIATED   DB "Slot not instantiated",0
        MSG_INSUFFICIENT_MEMORY     DB "Insufficient memory",0
        MSG_FRAMING_ERROR           DB "Framing error",0
        MSG_MID_BAD_BOUNDS          DB "Mid position beyond length", 0
MSG_DELETE_BAD_LENGTH DB "Delete length too large or small",0
        MSG_DELETE_BAD_POSITION DB "Delete position too low or high",0
       
        ErrorMessages DD MSG_NO_ERROR
DD MSG_INVALID_SLOT
DD MSG_INVALID_SLOT_SIZE
                        DD MSG_STORE_NULL
                        DD MSG_SLOT_NOT_OCCUPIED
                        DD MSG_SLOT_NOT_INSTANTIATED
                        DD MSG_INSUFFICIENT_MEMORY
                        DD MSG_FRAMING_ERROR
                        DD MSG_MID_BAD_BOUNDS
                        DD MSG_DELETE_BAD_LENGTH
DD MSG_DELETE_BAD_POSITION


If I have an error number less than 10, I can have something like

  mov ecx, 2
  mov edx, ErrorMessages[ecx]

and edx will contain the address of the 3rd error message. If, however, I have an error number of 10, then edx ends up with an address somewhere out beyond the orbit of Saturn. In the words of Julius Sumner Miller, "Why is it so?"

Kind regards,
Bruce.

sinsi

Because your ErrorMessages table is DWORDs, you need to multiply your error by 4

  mov ecx, 2
  mov edx, ErrorMessages[ecx*4]

Error 10, by your code, points to half of MSG_INVALID_SLOT_SIZE and half of MSG_STORE_NULL (something like 1c000040) -> access violation.
Light travels faster than sound, that's why some people seem bright until you hear them.

axtens

 :U Right on, sinsi, that worked a treat.

Thanks very much.

Bruce.

sinsi

Light travels faster than sound, that's why some people seem bright until you hear them.