home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / ins_msb / 9005 / mhstfill.asm < prev    next >
Assembly Source File  |  1990-05-01  |  2KB  |  98 lines

  1. Extrn StringAssign:far
  2.  
  3. ;PROGRAM - MHSTFILL.ASM
  4.  
  5. Code segment para public 'code'
  6. assume cs:Code
  7.     
  8. Public FillStringArray
  9. FillStringArray Proc Far
  10. ; DIM Array$(NumberOfElements)
  11. ; CALLS FillStringArray
  12. ;                (Array$(LowestElementToFill%))
  13.  
  14. ; This routine works with near and far strings.
  15.  
  16. Comment |
  17.  
  18.     Note the "S" in the CALLS syntax. This forces
  19.     BC to pass the    pointer to the array descriptors
  20.     instead of just passing a pointer to a *copy*
  21.     of the first descriptor. |
  22.  
  23.     push bp
  24.     mov bp,sp
  25.     push si
  26.     push di
  27.     push ds
  28.     cld                ; Clear the direction flag.
  29.  
  30.     mov bp,[bp+6]    ; Point to 1st string descriptor
  31.     mov ax,cs
  32.     mov ds,ax        ; Point DS:SI at our data.
  33.     mov si,offset NumberOfDataItems
  34.     lodsw                ; Move number of data items
  35.     mov cx,ax        ;   into CX register for count.
  36. FillStringLoop:
  37.     lodsw                ; Length of our data item
  38.     or ax,ax            ; is it a zero? (null string)
  39.     jz SkipThisString    ; yes - don't process it
  40.     
  41.     push cx                ; save our critical registers
  42.     push si    
  43.     push ax
  44.     push ds
  45.     
  46.     mov bx,ss    ; StringAssign expects DS=DGROUP,
  47.     mov ds,bx    ;   but docs don't tell you that!
  48.     push cs        ; segment of string to be assigned
  49.     push si        ; offset of string 
  50.     push ax        ; length of string
  51.     push ss        ; segment of descriptor
  52.     push bp        ; offset of descriptor
  53.     xor ax,ax    ; function 0 - assign string
  54.     push ax
  55.     call StringAssign        ; assign the string
  56.  
  57.     pop ds
  58.     pop ax                ; retrieve critical registers
  59.     pop si
  60.     add si,ax            ; point to next item's length
  61.     pop cx
  62. SkipThisString:
  63.     add bp,4                ; point to next descriptor
  64.     loop FillStringLoop        ; cook until done    
  65.     pop ds
  66.     pop di
  67.     pop si
  68.     pop bp
  69.     ret 4
  70.  
  71. FillStringArray Endp
  72.     
  73. NumberOfDataItems    dw 10     ; # of elements to fill.
  74.                     
  75. ActualData    dw 3             ; Length of string
  76.         db 'One'        ; String data (both repeated for
  77.         dw 3            ; each data element.
  78.         db 'Two'
  79.         dw 5
  80.         db 'Three'
  81.         dw 4
  82.         db 'Four'
  83.         dw 4
  84.         db 'Five'
  85.         dw 3
  86.         db 'Six'
  87.         dw 5
  88.         db 'Seven'
  89.         dw 5
  90.         db 'Eight'
  91.         dw 4
  92.         db 'Nine'
  93.         dw 3
  94.         db 'Ten'
  95.  
  96. Code ends
  97.     end
  98.