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

  1. ;void  set_bits_8(value,replacement,position,bits)
  2. ;  unsigned char  *value,replacement,position,bits;
  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_bits_8
  10. _set_bits_8 proc near
  11.     push bp            ;
  12.     mov  bp,sp        ;set up stack frame
  13.     push di            ;
  14.     cmp  _memory_model,0    ;near or far?
  15.     jle  begin        ;jump if near
  16.     inc  bp            ;else add 2 to BP
  17.     inc  bp            ;
  18. begin:    mov  _error_code,0    ;clear _error_code
  19.     cmp  _memory_model,2    ;data near or far?
  20.     jb   L0            ;jump if near
  21.     les  di,dword ptr[bp+4] ;ptr to Value
  22.     inc  bp            ;add 2 to BP since dword ptr
  23.     inc  bp            ;
  24.     jmp  short L00        ;
  25. L0:    mov  ax,ds        ;ES = DS
  26.     mov  es,ax        ;
  27.     mov  di,[bp+4]        ;
  28. L00:    mov  cl,[bp+10]        ;number bits
  29.     inc  _error_code    ;1 = zero bits
  30.     or   cl,cl        ;error check
  31.     jz   L1            ;quit if zero bits
  32.     mov  dl,0FFH        ;all 1s in DL
  33.     shl  dl,cl        ;field-width of 0s
  34.     not  dl            ;field-width of 1s
  35.     mov  al,[bp+6]        ;replacement value
  36.     and  al,dl        ;clear superfluous bits
  37.     mov  bl,cl        ;copy Bits to BL
  38.     mov  cl,[bp+8]        ;Position
  39.     inc  _error_code    ;2 = position out of range
  40.     cmp  cl,7        ;in range?
  41.     ja   L1            ;quit if not        
  42.     add  bl,cl        ;add number bits
  43.     inc  _error_code    ;3 = field doesn't fit
  44.     cmp  bl,8        ;does it fit?
  45.     ja   L1            ;quit if error
  46.     shl  al,cl        ;shift value to position
  47.     shl  dl,cl        ;shift mask to position
  48.     not  dl            ;reverse mask
  49.     and  es:[di],dl        ;clear field
  50.     or   es:[di],al        ;write new bits
  51.     mov  _error_code,0    ;success, return 0
  52. L1:    pop  di            ;
  53.     pop  bp            ;
  54.     cmp  _memory_model,0    ;quit
  55.     jle  quit        ;
  56.     db   0CBh        ;RET far
  57. quit:    ret            ;RET near
  58. _set_bits_8 endp
  59. _TEXT    ENDS
  60.     END
  61.