What is meant by read-modify -write in register access generally?

Why do we need to do write a data in to a register using this sequence of read-modify-write order?

In reply to Arun_Rajha:

  
 /*Let's assume 32bit ctrl_reg register with 2 different bit-field.
   data_ctrl(22bit), clk_ctrl(10bit)*/
  _______________________
  | 31  :  10 | 9 : 0    | 
  | data_ctrl | clk_ctrl |
  |___________|__________|  

  // you want to modify data_ctrl bit-field and don't want to change the clk_ctrl bit-field value. 
  // But when you write the register, it will modify all 32bit value.
  
  // so first read the register data, modify the read data then write the register

  tmp_data = *ctlr_reg; // ctrl_reg read operation
  tmp_data = data_ctrl | (tmp_data & 0x0000_003FF); // modify the data
  *ctlr_reg = tmp_data;  // ctrl_reg write operation

In reply to Rahulkumar Patel:

@Rahulkumar

Thanks you for answering,
I have been pondering this in my head for long time.

In reply to Rahulkumar Patel:

In reply to Arun_Rajha:

  
/*Let's assume 32bit ctrl_reg register with 2 different bit-field.
data_ctrl(22bit), clk_ctrl(10bit)*/
_______________________
| 31  :  10 | 9 : 0    | 
| data_ctrl | clk_ctrl |
|___________|__________|  
// you want to modify data_ctrl bit-field and don't want to change the clk_ctrl bit-field value. 
// But when you write the register, it will modify all 32bit value.
// so first read the register data, modify the read data then write the register
tmp_data = *ctlr_reg; // ctrl_reg read operation
tmp_data = data_ctrl | (tmp_data && 0x0000_003FF); // modify the data
*ctlr_reg = tmp_data;  // ctrl_reg write operation

Be careful with logical operation “&&”. It wont work as your expectation with this statement. It should be bitwise operation “&”.


tmp_data = data_ctrl | (tmp_data & 0x0000_003FF); 

In reply to chris90:

It was typo. Thanks for correcting it.