Post Reply 
How many elements in a CASE ?
02-29-2016, 01:40 AM
Post: #12
RE: How many elements in a CASE ?
(02-24-2016 07:53 AM)cyrille de brébisson Wrote:  Hello,

Case will involve a lot of tests (all the tests needs to be tested one at a time)... and this can be quite slow for byte 255....

A better approach would be to check bit 7, 6, 5... in row. Note that you can use var(index) access on integers to extract a single bit!
This would 1: change your case(256) to a series of if/then/else and lead to a consistent 8 tests per instruction.

Or, you could have your evaluation code for instruction n be called Ins_n and then do an expr("Ins_"+n+"(parameters if needed)");
This would replace your 256 long case by a single line and would be much faster than the case. I am not sure if it would be faster than the 8 tests solution.

You can also use a list (l) that contains the code for each of the instructions and do eval(l(instruction)).

Cyrille

Hello Cyrille,

I spent much of the day today converting my program over to use the second of your suggestions. Even though I have only about half of the 8080 instructions coded, and I've tested only a few for actually working correctly (rather than simply being syntactically correct), I can visually see that the program is running much faster.

I am so pleased to realize that I can code the 8080 simulator program as a relatively small mainline program and 256 tiny programs that each handle one instruction. The EVAL("INS_"+n) statement is working great for me, rather than multiple CASE statements.

Thank you so much for taking the time to assist me with this effort. I greatly appreciate your (and Tim's) attention and assistance.

smp
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
How many elements in a CASE ? - smp - 02-22-2016, 12:18 PM
RE: How many elements in a CASE ? - smp - 02-22-2016, 11:02 PM
RE: How many elements in a CASE ? - smp - 02-23-2016, 08:25 PM
RE: How many elements in a CASE ? - smp - 02-23-2016, 11:31 PM
RE: How many elements in a CASE ? - smp - 02-24-2016, 12:40 PM
RE: How many elements in a CASE ? - smp - 02-29-2016 01:40 AM



User(s) browsing this thread: 1 Guest(s)