home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / apl / sharp / ctoh.asm < prev    next >
Assembly Source File  |  1988-03-21  |  3KB  |  63 lines

  1. ; 1854339PC360:DOSX:CTOH.IPSN.ASM.9.33113. */
  2.           PAGE    60,132
  3. ; convert character string to apl hex for printing
  4. ; this routine is called using the dosx call function
  5. ; the data to be converted is catenated to end of code
  6. ; the result is
  7. ;   the dosx result code 00 00;
  8. ;   registers ax,bx,cx,dx,cs,ds,es,ss,si,di,sp,bp,flags,
  9. ;   the data between ds:si and ds:di
  10. ; for example an argument of quadav produces a result of
  11. ; '00 00;',ax,bx,...sp,flags,     32 bytes rc and registers
  12. ; '00010203...feff'               512 bytes apl hex data
  13. ; if the argument and result don't fit in the buffer
  14. ; the result is the result code and registers
  15. ctoh     proc  far
  16. ctseg  segment byte public ;all segment registers point here
  17.          assume cs:ctseg,ds:ctseg,ss:ctseg,es:ctseg
  18. ; linkeditor will complain about no stack segment, let it
  19. axval    dw    string   ;ax is address of string
  20. ; si and di point to end+1 of string
  21. bxval    dw    0
  22. cxval    dw    0
  23. dxval    dw    0
  24. entpt:                  ;entry point is always address 8
  25.          push  si       ;save source index
  26.          mov   si,ax    ;start of data string
  27.          mov   cx,di    ;end of string
  28.          sub   cx,ax    ;length of string
  29.          jz    done     ;no string
  30.          mov   ax,cx
  31.          add   ax,ax    ;length of result (twice arg length)
  32.          add   ax,di    ;end of result
  33.          add   ax,200   ;room for stack
  34.          cmp   ax,sp
  35.          jae   done     ;no room, return empty result
  36.          xor   ax,ax
  37. next:
  38.          lodsb          ;get source byte into al
  39.          push  ax       ;save byte
  40.          mov   bx,ax
  41.          shr   bx,1     ;shift top half byte down
  42.          shr   bx,1
  43.          shr   bx,1
  44.          shr   bx,1
  45.          mov   al,table[bx] ; get apl char for first half
  46.          stosb          ;store value in result
  47.          pop   bx       ;get data byte
  48.          and   bx,0fh   ;remove top half byte
  49.          mov   al,table[bx] ; get apl char for second half
  50.          stosb          ;store value in result
  51.          loop  next     ;decrement cx and jump if not zero
  52. done:                   ;conversion complete
  53. ;di now points to end of result
  54.          pop   si
  55. ;si points at start of result
  56.          ret            ;return to dosx
  57. table    db    8ch,8dh,8eh,8fh,90h,91h,92h,93h ;apl 0-7
  58.          db    94h,95h,56h,57h,58h,59h,5ah,5bh ;apl 8,9,a-f
  59. string:                 ;data starts here
  60. ctseg    ends           ;end segment
  61. ctoh     endp           ;end procedure
  62.          end            ;start address 0  for exe2bin
  63.