home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH08 / GETARRAY.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-24  |  2.4 KB  |  103 lines

  1. ; GETARRAY.ASM
  2. ;
  3. ; This module contains the GetArray input routine.  This routine reads a
  4. ; set of values for a row of some array.
  5.  
  6.         .386
  7.         option    segment:use16
  8.  
  9.         .nolist
  10.         include    stdlib.a
  11.         .list
  12.  
  13.         include    matrix.a
  14.  
  15.  
  16.  
  17. ; Some local variables for this module:
  18.  
  19. localdseg    segment    para public 'LclData'
  20.  
  21. NumElements    word    ?
  22. ArrayPtr    dword    ?
  23.  
  24. Localdseg    ends
  25.  
  26.  
  27.  
  28.  
  29. InpSeg        segment    para public 'input'
  30.         assume    ds:Localdseg
  31.  
  32. ; GetArray-    Read a set of numbers and store them into an array.
  33. ;
  34. ;        On Entry:
  35. ;
  36. ;            es:di points at the base address of the array.
  37. ;            ax contains the number of elements in the array.
  38. ;
  39. ;        This routine reads the specified number of array elements
  40. ;        from the user and stores them into the array.  If there
  41. ;        is an input error of some sort, then this routine makes
  42. ;        the user reenter the data.
  43.  
  44. GetArray    proc    far
  45.         pusha                ;Preserve all the registers
  46.         push    ds            ; that this code modifies
  47.         push    es
  48.         push    fs
  49.  
  50.         ifdef    debug
  51.         print
  52.         char    "Inside GetArray, # of input values =",0
  53.         puti
  54.         putcr
  55.         endif
  56.  
  57.         mov    cx, Localdseg        ;Point ds at our local
  58.         mov    ds, cx            ; data segment.
  59.  
  60.         mov    wp ArrayPtr, di        ;Save in case we have an
  61.         mov    wp ArrayPtr+2, es    ; error during input.
  62.         mov    NumElements, ax
  63.  
  64. ; The following loop reads a line of text from the user containing some
  65. ; number of integer values.  This loop repeats if the user enters an illegal
  66. ; value on the input line.
  67. ;
  68. ; Note: LESI is a macro from the stdlib.a include file.  It loads ES:DI
  69. ; with the address of its operand (as opposed to les di, InputLine that would
  70. ; load ES:DI with the dword value at address InputLine).
  71.  
  72. RetryLp:    lesi    InputLine        ;Read input line from user.
  73.         gets
  74.         mov    cx, NumElements        ;# of values to read.
  75.         lfs    si, ArrayPtr        ;Store input values here.
  76.  
  77. ; This inner loop reads "ax" integers from the input line.  If there is
  78. ; an error, it transfers control to RetryLp above.
  79.  
  80. ReadEachItem:    call    geti            ;Read next available value.
  81.         jc    BadGA
  82.         mov    fs:[si], ax        ;Save away in array.
  83.         add    si, 2            ;Move on to next element.
  84.         loop    ReadEachItem        ;Repeat for each element.
  85.  
  86.         pop    fs            ;Restore the saved registers
  87.         pop    es            ; from the stack before
  88.         pop    ds            ; returning.
  89.         popa
  90.         ret
  91.  
  92. ; If an error occurs, make the user re-enter the data for the entire
  93. ; row:
  94.  
  95. BadGA:        print
  96.         char    "Illegal integer value(s).",cr,lf
  97.         char    "Re-enter data:",0
  98.         jmp    RetryLp
  99. getArray    endp
  100.  
  101. InpSeg        ends
  102.         end
  103.