home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PJ8_3.ZIP / LNKTBL1.ASM < prev    next >
Assembly Source File  |  1990-02-26  |  2KB  |  114 lines

  1.     title    listing one - link time table
  2.     include    asm.inc
  3.  
  4.     .stack
  5.     .data
  6.     .data?
  7.     extrn    argv:dword,argc:word
  8.  
  9. CMD_DAT    segment byte public 'CONST'
  10. command_table label byte
  11.     db    'one',0,'two',0
  12. CMD_DAT ends
  13. CMD_END    segment byte public 'CONST'
  14.     db    0
  15. CMD_END ends
  16. DGROUP    group    CMD_DAT,CMD_END
  17.  
  18.     .code
  19.     extn    outchr_asciiz,outchr_space,exit_program,startup
  20.  
  21. ;;    main
  22. ;
  23. main    proc
  24.     mov    ax,@data        ; compensate for MS-LINK bug
  25.     mov    ss,ax
  26.     mov    sp,offset stack
  27.  
  28.     mov    ax,sp            ; initialize segments, argv, argc, etc
  29.     call    startup
  30.  
  31.     mov    cx,argc[bp]
  32.     jcxz    mai3            ;  if no arguments
  33.  
  34.     mov    ax,@data
  35.     mov    ds,ax
  36.  
  37.     mov    bx,0
  38. mai1:    lea    si,command_table
  39.  
  40.     les    di,argv[bp]
  41.     mov    di,es:[di+bx]
  42.     add    bx,2
  43.  
  44.     call    search_asciiz_table
  45.     jc    mai2
  46.     call    outchr_asciiz
  47.     call    outchr_space
  48.  
  49. mai2:    loop    mai1
  50.  
  51. mai3:    jmp    exit_program
  52. main    endp
  53.  
  54.  
  55. ;;    search asciiz table
  56. ;
  57. ;    entry    DS:SI    asciiz table
  58. ;        ES:DI    search string
  59. ;    exit    SI    matching table entry
  60. ;        Cf    if search string not found
  61. ;    uses    AX
  62. ;
  63. search_asciiz_table proc
  64.     jmp    sat2
  65.  
  66. sat1:    call    strcmp            ; compare search string with table
  67.     je    sat3            ;  if match
  68.     call    strskp            ;  else skip table entry
  69.  
  70. sat2:    cmp    bptr [si],NULL_CHAR    ; check for end of table
  71.     jne    sat1            ;  if more table entries
  72.     stc                ;  else indicate string not found
  73.  
  74. sat3:    ret
  75. search_asciiz_table endp
  76.  
  77.  
  78. ;;    strcmp
  79. ;
  80. ;    entry    DS:SI    string 1
  81. ;        ES:DI    string 2
  82. ;    exit    Zf    if equal (Cf=0)
  83. ;        Cf    if string 2 > string 1
  84. ;    uses    AX
  85. ;
  86. strcmp    proc
  87.     pushm    di,si
  88. scp1:    lodsb
  89.     mov    ah,es:[di]
  90.     inc    di
  91.     or    ax,ax
  92.     jz    scp2            ; if end of both strings (equal)
  93.     cmp    al,ah
  94.     je    scp1            ; if strings equal so far
  95. scp2:    popm    si,di
  96.     ret
  97. strcmp    endp
  98.  
  99.  
  100. ;;    strskp
  101. ;
  102. ;    entry    DS:SI    string pointer
  103. ;    exit    SI    updated to byte past NULL
  104. ;    uses    AX
  105. ;
  106. strskp    proc
  107.     lodsb
  108.     cmp    al,0
  109.     jne    strskp
  110.     ret
  111. strskp    endp
  112.  
  113.     end    main
  114.