Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/12/06 10:10
Modified:
  07/12/06 10:17

Read: times


 
#120068 - FAQ: table lookup
I was looking at the faqs briefly, and would like to comment on the table lookup faq, particularly, to the "text lookup example". I think it is not approproate to use the new "Add information to FAQ" here.

First, the texts table is:
      msg_table:
      db 'Begin '
      db 'More '
      db 'Enter >'
      db 'Quit ? '

and the comment says, "Also note each message is 7 characters long. ". Well, it is obviously not so (and seen clearly thanks to unproportional font) - the first entry is 6 characters, the second is 5 characters long. Also, it would be good to say something like "we arranged it so appending spaces after the shorter texts, because this way the lookup will be simple (or possible at all)".

Then, the "sanity" check on the input values (0..3 allowed) goes like:
    ; *** Input Validation ***
      ; ************************
      jz msg_index ;If acc=0 we have an acceptable value.
      cjne a,#3,eval_acc ;We have a non-zero value is other than 3?
      jmp msg_index ;No it is 3, a valid value.
      ; *** It's not either a 0 or 3 value ***
      ; *** Test for an invalid value ***
      eval_acc:
      jnc input_err ;If we didn't carry the value exceeds that allowable.

Well, both jz msg_index and jmp msg_index are redundant. Not that it will harm, but I think a FAQ should be somehow "nice".

Then, the pointer is calculated, multiplying the input by 7 (the string length as stated above):
   mov b,#7 ;Init msg length multiplier
      mul ab ;Multiply Index (Element Number) by Element size.
      ; ************************************
      ; *** One Approach to Table Access ***
      ; ************************************
      add a,dpl ;Add the Index Value to the low byte of dptr
      mov dpl,a
      mov a,dph ;Correct for any carry (cross page boundry)
      addc a,#0
      mov dph,a

I am confused by the "One approach to table access" comment - what does it refer to?
Also, it would be nicer to add the full 16-bit result of multiplication (offset) to the table base address (replace addc a,#0 by addc a,b) - I know that given the item length=7 and number of items in table=4, b will always be 0, but in this way, certain flexibility is gained.

Later, it is remarked, that the character can be zero terminated and the transmitting routine stops on this zero rather than uses a character counter. When mentioning such alternatives, I'd also add another alternatives to table lookup: a possibility to make a table search rather than lookup (sparing the padding spaces and making it more flexible), and the lookuptable of pointers into the strings table.

Jan Waclawek

PS. If it would be a true wiki, I'd already change it myself, sparing Craig the double work... :-)

PS2 added later: I dug out the original post, it seems the code formatting got lost somehow, maybe it would be good to restore it?

List of 8 messages in thread
TopicAuthorDate
FAQ: table lookup            01/01/70 00:00      
   you are a Wikid individual            01/01/70 00:00      
      beef?            01/01/70 00:00      
   Yours now            01/01/70 00:00      
      what a beautiful 'gotcha'            01/01/70 00:00      
      OK, work in progress...            01/01/70 00:00      
         Stuff            01/01/70 00:00      
            This gives me an idea ...            01/01/70 00:00      

Back to Subject List