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

  1. ;void  set_mem_8(replacement,position,bits,segment,offset);
  2. ;  unsigned char   replacement,position,bits;
  3. ;  unsigned short  segment,offset;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.  
  8. _TEXT    SEGMENT  BYTE PUBLIC 'CODE'
  9.     ASSUME CS:_TEXT
  10.     PUBLIC _set_mem_8
  11. _set_mem_8 proc near
  12.     push bp            ;
  13.     mov  bp,sp        ;make stack frame
  14.     push di            ;
  15.     cmp  _memory_model,0    ;near or far?
  16.     jle  begin        ;jump if near
  17.     inc  bp            ;else add 2 to BP
  18.     inc  bp            ;
  19. begin:    mov  _error_code,0    ;clear _error_code
  20.     les  di,dword ptr[bp+12] ;ES:DI pts to memory
  21.     mov  cl,[bp+8]        ;number bits
  22.     inc  _error_code    ;1 = zero bits
  23.     or   cl,cl        ;error check
  24.     jz   L1            ;quit if zero bits
  25.     mov  dl,0FFH        ;all 1s in DL
  26.     shl  dl,cl        ;field-width of 0s
  27.     not  dl            ;field-width of 1s
  28.     mov  al,[bp+4]        ;replacement value
  29.     and  al,dl        ;clear superfluous bits
  30.     mov  bl,cl        ;copy Bits to BL
  31.     mov  cl,[bp+6]        ;Position
  32.     inc  _error_code    ;2 = position out of range
  33.     cmp  cl,7        ;greater than 7?
  34.     ja   L1            ;quit if so
  35.     add  bl,cl        ;add number bits
  36.     inc  _error_code    ;3 = field too large
  37.     cmp  bl,8        ;does it fit?
  38.     ja   L1            ;quit if error
  39.     shl  al,cl        ;shift value to position
  40.     shl  dl,cl        ;shift mask to position
  41.     not  dl            ;reverse mask
  42.     and  es:[di],dl        ;clear field
  43.     or   es:[di],al        ;write new bits
  44.     mov  _error_code,0    ;success, return 0
  45. L1:    pop  di            ;
  46.     pop  bp            ;
  47.     cmp  _memory_model,0    ;quit
  48.     jle  quit        ;
  49.     db   0CBh        ;RET far
  50. quit:    ret            ;RET near
  51. _set_mem_8 endp
  52. _TEXT    ENDS
  53.     END
  54.