home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / cexpress / files / asempath.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  2.7 KB  |  98 lines

  1. ;void  assemble_path(return_string,array_position,tree_array);
  2. ;  char  *tree_array,*return_string;
  3. ;  unsigned short  array_position;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.     EXTRN  _tree_array_size:word
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME CS:_TEXT
  11.     PUBLIC _assemble_path
  12. _assemble_path proc near
  13.     push bp                ;
  14.     mov  bp,sp            ;
  15.     push di                    ;
  16.     push si                    ;
  17.     cmp  _memory_model,0        ;near or far?
  18.     jle  begin            ;jump if near
  19.     inc  bp                ;else add 2 to BP
  20.     inc  bp                ;    
  21. begin:    push ds                ;
  22.     jmp  short start        ;jump over local data
  23.     mem_model db ?            ;keep copy, since DS changed
  24. start:    mov  al,_memory_model        ;
  25.     mov  cs:mem_model,al        ;
  26.     cmp  _memory_model,2        ;data near or far?
  27.     jb   L0                ;jump if near
  28.     les  di,dword ptr[bp+4]        ;ES:DI pts to return string
  29.     inc  bp                ;add 2 to BP since dword ptr
  30.     inc  bp                ;
  31.     jmp  short L00            ;
  32. L0:    mov  ax,ds            ;ES = DS
  33.     mov  es,ax            ;
  34.     mov  di,[bp+4]            ;
  35. L00:    mov  byte ptr es:[di],0        ;null string if error
  36.     mov  _error_code,1        ;1 = _tree_array_size out of range
  37.     mov  ax,_tree_array_size    ;ArrayPosition OK?
  38.     mov  bx,[bp+6]            ;
  39.     or   bx,bx            ;
  40.     jz   L9                ;
  41.     cmp  bx,ax            ;
  42.     ja   L9                ;quit if not
  43.     dec  _error_code        ;0 = no error
  44.     sub  bx,bx            ;counts return strg length
  45. L1:    mov  ax,[bp+6]            ;fetch ArrayPosition
  46. L2:    cmp  cs:mem_model,2        ;
  47.     jb   L3                ;
  48.     lds  si,dword ptr[bp+8]        ;DS:SI pts to TreeArray
  49.     jmp  short L4            ;
  50. L3:    mov  si,[bp+8]            ;near case
  51. L4:    add  si,21            ;start at array element 1
  52.     dec  ax                ;offset from 0
  53.     mov  dl,21            ;bytes per record
  54.     mul  dl                ;offset
  55.     add  si,ax            ;add to ptr    
  56.     sub  cx,cx            ;get string length
  57.     push si                ;
  58. L5:    cmp  byte ptr[si],0        ;
  59.     je   L6                ;
  60.     inc  cx                ;
  61.     inc  si                ;
  62.     jmp  short L5            ;
  63. L6:    pop  si                ;
  64.     add  bl,cl            ;add to tally
  65.     inc  bl                ;plus one for backslash
  66.     or   bh,bh            ;first pass?
  67.     jz   L7                ;don't copy string if so
  68.     add  si,cx            ;pt SI to end of string
  69.     dec  si                ;
  70.     std                ;
  71.     rep  movsb            ;copy chars to return strg
  72.     mov  byte ptr es:[di],'\'    ;write in the slash
  73.     dec  di                ;
  74.     inc  si                ;adjust for terminator
  75. L7:    cmp  word ptr [si+13],0        ;check Parent field
  76.     jz   L8                ;
  77.     mov  ax,[si+13]            ;get ptr to Parent element
  78.     jmp  short L2            ;
  79. L8:    or   bh,bh            ;first pass?
  80.     jnz  L9                ;quit if not
  81.     add  di,bx            ;forward strg ptr
  82.     mov  byte ptr es:[di],0        ;set terminating null
  83.     dec  di                ;minus one for terminator byte
  84.     inc  bh                ;flag that second pass
  85.     jmp  short L1            ;this time, copy over strings
  86. L9:    pop  ds                ;
  87.     pop  si                    ;
  88.     pop  di                    ;
  89.     pop  bp                ;
  90.     cld                ;
  91.     cmp  _memory_model,0        ;quit
  92.     jle  quit            ;
  93.     db   0CBh            ;RET far
  94. quit:    ret                ;RET near
  95. _assemble_path endp
  96. _TEXT    ENDS
  97.     END
  98.