Switch в masm

Тема в разделе "WASM.ASSEMBLER", создана пользователем MrMiXeR, 8 авг 2009.

  1. PSR1257

    PSR1257 New Member

    Публикаций:
    0
    Регистрация:
    30 ноя 2008
    Сообщения:
    933
    wsd

    See the demo-description:

    PARAMFILE1.ini
    [Section1]
    Param1=SomeParam1Value
    Param2=SomeParam2Value
    ...
    [Section2]
    Param1Sec2=SomeParam1Value
    Param2Sec2=SomeParam2Value
    ...
    PARAMFILE2.ini
    [Section1]
    Param1Sec1=SomeParam1Value
    ...

    Structure of these files are like the standard Windows ini-files. Application has a number of calls like this:
    char Param[128];
    // Read Param1Sec1 value from file "PARAMFILE2.ini", section "Section1" ReadIniParameters("PARAMFILE2.ini", "Section1", "Param1Sec1", &Param);

    It is required to analyze different methods of creating the well-ordered data lists, which allow to provide the maximum access speed and to choose the most optimal. Main requirement is the speed, because 1) these functions are called quite often; 2) the application is written in C, but binaries are executed by something like virtual Forth machine.

    So functions like ReadIniParameters should be optimized for speed.

    Comments:
    Used programming language is C (ANSI).
    Time-consuming building of indexes for access to the configuration data is allowed on the initialization stage.

    Solution:
    I performed analysis of different algorithms for sorting and building index files. I decided to use CRC (CRC16) for indexes and to used “normalized” CRC value, in that way used the hashing method. One of the reasons of this choice is existence of the System CRC16 API function which can quickly calculate CRC16 of the data block by application request.
    ...
    Description of the index file creation:
    Summary number of parameters in all sections and all files is Nparams. When adding a new parameter from the INI file to the index file, following actions are taking place:

    char FullParamName[128];
    // Create index for each parametr
    strcpy(FullParamName, FileName); //example:FullParamName="FILE1.INI"
    strcat(FullParamName, SectName); //example:FullParamName="FILE1.INISection4"
    strcat(FullParamName, ParamName); //example:"FILE1.INISection4Param8"
    // Calculate CRC from "Full Parametr name"
    tmpCRC= CalculateBlockCRC16(strlen(FullParamName), &FullParamName);
    // "Normalize" CRC for index file
    tmpCRC= tmpCRC/NParams;

    Each parameter is added to the index file based on the tmpCRC value. Index file consists of the Nparams records, each contains a set of references to the real values FileName+SectName+ParamName. In the common case there can be more than one refernces, because of the CRC16 collisions. In this case references will link to the different parameters and we need to compare them in the series:

    Index file
    ...
    CRC16_j-1/NParams
    CRC16_j/NParams -> link to (File+Sect+Param)1, (File+Sect+Param)2...
    ...
    When requesting the parameter’s value, ReadIniParameters function calculates the CRC16 from the (FileName+SectName+ParamName). Using the normalized value (CRC16/NParams) it quickly selects (using lseek) the small set of references to the real values of (FileName+SectName+ParamName) to check and compares them for the exact equality:

    typedef struct tag_tIndexRecord
    {
    long ParamLink; // Link to real FileName, Section, ParamName
    long NextIndexRec; // Link to next index (if exists)
    } tIndexRecord;

    int ReadIniParameters(char *FileName, char *Section, char *Param, char *Result)
    {
    WORD tmpCRC; char FullParamName[128]; int h;
    tIndexRecord InRec;
    tFileSecParam FileSecParam; // Calculate CRC from "Full Parameter name"

    strcpy(FullParamName, FileName);
    strcat(FullParamName, Section); strcat(FullParamName, Param);
    tmpCRC= CalculateBlockCRC16(strlen(FullParamName), &FullParamName); // "Normalize" CRC for index file
    tmpCRC= tmpCRC/NParams;

    // Read first index record
    if ( (h= open("fileind.ind", O_RDWR)) < 0 ) return(0);
    lseek(h, tmpCRC*sizeof(tIndexRecord), SEEK_SET);
    read(h, InRec, sizeof(tIndexRecord));
    while ( InRec.ParamLink != -1 )
    {
    lseek(h, ParamLink, SEEK_SET);
    read(h, FileSecParam, sizeof(tFileSecParam));
    if ( !strcmp(FileSecParam.File, FileName) &&
    ...

    This algorithm allows to get configuration parameters at a high speed, and it’s speed very slowly grows with increasing the summary number of parameters Nparams.
     
  2. wsd

    wsd New Member

    Публикаций:
    0
    Регистрация:
    8 авг 2007
    Сообщения:
    2.824
    PSR1257
    спс
     
  3. Y_Mur

    Y_Mur Active Member

    Публикаций:
    0
    Регистрация:
    6 сен 2006
    Сообщения:
    2.494
    MrMiXeR
    http://www.wasm.ru/forum/viewtopic.php?pid=323810#p323810 => п3 в ответе
     
  4. Mikl___

    Mikl___ Супермодератор Команда форума

    Публикаций:
    14
    Регистрация:
    25 июн 2008
    Сообщения:
    3.787
  5. Microedition

    Microedition Active Member

    Публикаций:
    0
    Регистрация:
    5 июн 2008
    Сообщения:
    814
    Я всегда говорил, если хотите использовать switch, if-else, for, do-while,
    то программируйте на си, нечего асм загромждать этими конструкциями.
     
  6. MrMiXeR

    MrMiXeR New Member

    Публикаций:
    0
    Регистрация:
    27 июн 2008
    Сообщения:
    97
    все. всем спасибо. вопрос закрыт
     
  7. Rockphorr

    Rockphorr Well-Known Member

    Публикаций:
    0
    Регистрация:
    9 июн 2004
    Сообщения:
    2.622
    Адрес:
    Russia
    Microedition
    ну почему си можно и на асме

    ИМХО:
    первое что небходимо - принести в жертву некоторую часть быстродействия другими словами отдавать себе полный отчет в том что строящийся механизм не будет супер быстрым

    второе что нужно - разработать макос так чтоб вым было удобно
    мне например удобно так в 16 разрядных дос проектах
    Код (Text):
    1. ;=======[ STRUCTURE ]=============================
    2. Word_far\
    3.     STRUC
    4. Word_far_ID\
    5.     WORD    ?
    6. Word_far_label\
    7.     DWORD   ?
    8. Word_far\
    9.     ENDS
    10.  
    11. ...
    12.  
    13. ;;======[ MACRO ]=================================
    14. @Seek_by_WORD\
    15.     MACRO\
    16.         switch:req,\
    17.         segment_register:req,\
    18.         index_register:req,\
    19.         power:req
    20.     LOCAL\
    21.         $next,\
    22.         $exit
    23.     ;;----------------------------------------
    24. $next:
    25.     mov AX,WORD PTR\
    26.         segment_register:[index_register]
    27.     IF  @Fault
    28.     cmp AX,@Fault
    29.     ELSE
    30.     or  AX,AX
    31.     ENDIF
    32.     je  $exit
    33.     cmp AX,WORD PTR switch
    34.     je  $exit
    35.     sub index_register,power
    36.     jmp\
    37.     short   $next
    38. $exit:
    39.     ;;----------------------------------------
    40.     ENDM
    41.  
    42. ....
    43.  
    44.     Word_far\
    45.         <@Fault,Method_Fx>
    46.     Word_far\
    47.         <@Key_enter,Method_Enter>
    48.     Word_far\
    49.         <@Key_tab,Main_Method_Tab>
    50.  
    51. S0_Branches\
    52.     LABEL   Word_far
    53.  
    54. ...
    55.  
    56. @Load_DS_SI\
    57.         S0_Branches-SIZE(Word_far)
    58. @Seek_by_WORD\
    59.         DX,DS,SI,<SIZE(Word_far)>
    60.     stc
    61.     call    (Word_far PTR[SI])\
    62.         .Word_far_label
     
  8. Rockphorr

    Rockphorr Well-Known Member

    Публикаций:
    0
    Регистрация:
    9 июн 2004
    Сообщения:
    2.622
    Адрес:
    Russia
    упс опоздал