dharanikumarsrvn
Junior Member level 1

what is called read/modify/write in atmega 16 operation ?
PORTB=0x01; // this is a write operation
PORTB= PORTB | 0x01; // this is a RMW operation , it reads PORTB value, ORes it with 1 and then writes the result back
Actually this is not an RMW operation, at least it shouldn't regardless of compiler. This is an atomic operation, uninterruptible by other ISRs.Code:PORTB= PORTB | 0x01; // this is a RMW operation , it reads PORTB value, ORes it with 1 and then writes the result back
Do not use Read-Modify-Write instructions (SBI and CBI) to set or clear the MPCM bit.
The MPCM bit shares the same I/O location as the TXC Flag and this might accidentally
be cleared when using SBI or CBI instructions.
SBI and CBI are both Read-Modify-Write instructions so when PORTB= PORTB | 0x01; generates the following ASM code SBI 0x5,0 how is that not RMW ?Do not use Read-Modify-Write instructions (SBI and CBI) to set or clear the MPCM bit.
But on most AVR's (the devices which are exceptions to this rule have notes in the Register Summary section of the datasheet), even these so-called bitwise operations actually operate on the whole register, even if only one bit is being changed.
In a single instruction cycle (two clocks in this case), the whole I/O register is read into a scratch space, a single bit is modified, and the whole scratch register is written out to the I/O register again.
Actually that forum is a valuable source of info when it comes to AVR, any wrong answer in that forum would be confronted very fast from other members especially when it comes to things like that which are black or white.A post from another forum is not exactly what we were looking for to clear this issue
The compiler just shows the SBI instruction used, the claim that this is not a RMW instruction is made by you so the compiler has nothing to do as proof of what you say.Compiler's disassembler speaks for itself.
I refer to the same page too but it says 2 cycles for the device we talk about (m16)I will refer to page 123 of the instruction set pdf, where it is written that for tiny (which is an AVR as well), the sbi command is executed in 1 cycle. Is it possible for an RMW command to be executed in 1 cycle?
This is also from the mega16 datasheet in the I/O memory sectionWords : 1 (2 bytes)
Cycles : 2
Cycles XMEGA: 1
Cycles Reduced Core tinyAVR:1
How do these instruction write to all bits and don't use RMW operation?Some of the Status Flags are cleared by writing a logical one to them. Note that the CBI and SBI
instructions will operate on all bits in the I/O Register, writing a one back into any flag read as
set, thus clearing the flag. The CBI and SBI instructions work with registers $00 to $1F only.
Some of the Status Flags are cleared by writing a logical one to them. Note that, unlike most
other AVRs, the CBI and SBI instructions will only operate on the specified bit, and can therefore
be used on registers containing such Status Flags. The CBI and SBI instructions work with reg-
isters 0x00 to 0x1F only.
Now I suppose that the 'you' part went to the OP, unless you were talking to ATmega16 in second person. If assumed that you were talking to the OP, then the example clearly implied that this was an explanation of what is happening in commands level, which is completely wrong. Because RMW is also a more general term as you may know. And I still wonder what that "it" would be... The OP could easilly be driven to wrong conclusions reading this vague "explanation".RMW in any system is when you read a value , modify it and then write it back
PORTB= PORTB | 0x01; // this is a RMW operation , it reads PORTB value, ORes it with 1 and then writes the result back
I have replied thiswhat is called read/modify/write in atmega 16 operation ?
But you saidPORTB= PORTB | 0x01; // this is a RMW operation , it reads PORTB value, ORes it with 1 and then writes the result back
Using an image that showed this code compiled to an SBI instructionActually this is not an RMW operation
But you said that it isn'tSBI is a Read-Modify-Write instruction
You even justified it using this which doesn't apply in m16In SBI 0x5,0 read and write operations are missing. Only modify is there
In my last reply I think I proved beyond doubt that SBI is a RMW instruction in mega16 so now you try to justify your claim by saying that according to your definition a RMW operation can only be executed in memory and if it is executed in hardware like with the SBI in m16 then it is not considered that.for tiny (which is an AVR as well), the sbi command is executed in 1 cycle. Is it possible for an RMW command to be executed in 1 cycle
You mean the mega16 datasheet?Please post the link for each document you use as reference. Users don't have to search in the web, you could make it more convenient by posting the web location of those very documents.
It is interesting when you say that after accusing me for everything that comes in your mind from references I didn't provide to optimization levels to replies posted in other forums (I thought you said you didn't care for posts in other forums but you use them when it suits you) and all this to cover the fact that in no point in this thread you admit that SBI is a RMW operation unlike what you were saying in the first replies in order to prove that my code was wrong.I think that this thread has nothing more to offer to members, I am bowing out. OP took a clear picture.
:shock:insulting other members with expressions like “like it or not”,
Sorry, couldn't leave that unanswered. SBI in ATmega16 is an RMW operation. Nothing to do with other stuff I said in the last two posts.all this to cover the fact that in no point in this thread you admit that SBI is a RMW operation