home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CEXPRESS.ZIP / BITS.ASM / CHARBITS.ASM < prev    next >
Assembly Source File  |  1989-05-03  |  2KB  |  77 lines

  1. ;void set_char_bits(value,bits,position);
  2. ;  unsigned char  *value,*bits,position;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.  
  7. _TEXT    SEGMENT  BYTE PUBLIC 'CODE'
  8.     ASSUME CS:_TEXT
  9.     PUBLIC _set_char_bits
  10. _set_char_bits proc near
  11.     push bp            ;
  12.     mov  bp,sp        ;set stack frame
  13.     push di            ;
  14.     push si            ;
  15.     push ds            ;save DS
  16.     mov  _error_code,1    ;flag error
  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:    cmp  _memory_model,2    ;data near or far?
  22.     jb   L1            ;jump if near
  23.     les  di,dword ptr[bp+4] ;get addr of the byte
  24.     lds  si,dword ptr[bp+8] ;DS:SI pts to bit_string
  25.     add  bp,4        ;forward BP to compensate for dbl words
  26.     jmp  short L2        ;jump ahead
  27. L1:    mov  ax,ds        ;ES = DS
  28.     mov  es,ax        ;
  29.     mov  di,[bp+4]        ;near case
  30.     mov  si,[bp+6]        ;
  31. L2:    sub  dx,dx        ;will count number bits in field
  32.     push si            ;
  33. L3:    cmp  byte ptr[si],0    ;end of string?
  34.     je   L4            ;jump if so
  35.     inc  dx            ;inc counter
  36.     inc  si            ;forward ptr
  37.     cmp  dx,8        ;reached maximum yet?
  38.     jne  L3            ;loop if not
  39. L4:    pop  si            ;restore si
  40.     mov  bx,1        ;BX is mask
  41.     sub  cx,cx        ;clear CX
  42.     mov  cl,[bp+8]        ;get field start pos
  43.     add  cx,dx        ;add start position to number bits
  44.     cmp  cx,8        ;in range?
  45.     ja   L8            ;quit routine if not
  46.     dec  cx            ;adjust for shift
  47.     shl  bx,cl        ;mov mask bit to 1st pos
  48.     mov  cx,dx        ;get string length
  49.     jcxz L8            ;quit if null
  50.     sub  ax,ax        ;clear AX
  51.     mov  al,es:[di]        ;fetch value
  52. L5:    cmp  byte ptr[si],'1'    ;test a byte of the string
  53.     jne  L6            ;jump if not a '1'
  54.     or   ax,bx        ;else, set the bit
  55.     jmp  short L7        ;jump ahead
  56. L6:    not  bx            ;reverse the mask
  57.     and  ax,bx        ;clear the bit
  58.     not  bx            ;re-reverse the mask
  59. L7:    shr  bx,1        ;shift bit mask 1 to right
  60.     inc  si            ;pt to next byte of strg
  61.     loop L5            ;go do next byte
  62.     mov  es:[di],al        ;write the changed value
  63.     pop  ds            ;restore DS
  64.     dec  _error_code    ;0 = no error
  65.     jmp  short L9        ;jump ahead
  66. L8:    pop  ds            ;restore DS
  67. L9:    pop  si            ;
  68.     pop  di            ;
  69.     pop  bp            ;
  70.     cmp  _memory_model,0    ;quit
  71.     jle  quit        ;
  72.     db   0CBh        ;RET far
  73. quit:    ret            ;RET near
  74. _set_char_bits ENDP
  75. _TEXT    ENDS
  76.     END
  77.