 Hello and welcome to this video session on peak 16F877A Instruction Set, Bit Oriented Instructions. Myself Mr. Vipul Kondekar. In this video session at the end of the session student will be able to describe the bit oriented operations done by the peak microcontroller and will be able to explain the operation of 4 different bit oriented instructions available for the peak microcontroller. So these are the learning outcomes. In this presentation we will go for understanding bit oriented file register operations and then 4 different instructions which are dealing with the bit related operations with reference to their syntax, operands used for the instruction, what operation is carried out by that instruction, then the flags affected because of execution of that instruction, then description and one example for each. Now why we need bit oriented instructions? Basically when you are talking about microprocessor is different than microcontroller. Very important feature of microcontroller you say most of the instructions of the microcontroller can deal with the bits of the operand. Now talking about why we need bit oriented instruction, suppose LEDs are connected to port pin and I want to 8 LEDs are connected to 8 port pins of let us say port A. I want to turn on a particular LED. So if you want to turn on a particular LED one approach may be use byte oriented instruction and change byte accordingly. But instead of that if you go for a bit oriented instruction you can change a particular bit of a particular byte location and that will not affect other bit locations also. So we need bit oriented instructions to deal with the port pins of the microcontroller either you want to make it high low. So based on that we need bit oriented instructions. Now this is the format whenever you are having bit oriented instruction that up code of bit oriented instruction is going to be of 14 bits. But out of those 14 bits actual bit number 10 to bit number 13 these will be forming the up code they will decide which exactly is the bit oriented instruction. Then you want to deal with the bit. So which file register you want to use for bit oriented operation and which bit means file register is having size 8 bit. But which bit of that particular file register you want to deal with that will be decided by 3 bit bit address. So if you look at this B, B will be a 3 bit bit address of a byte which is part of file register and which file register though that file register will be that will be representing a particular file register 7 bit file register address will be there of a particular bank. Now talking about how much bit addressable area we got for peak microcontroller 16877 a microcontroller in 8051 microcontroller we say that we got 16 bytes of bit addressable area. Now let us try to understand the instructions. So let us start with the instruction BSF. This instruction is used for setting a particular bit of file register F. Now talking about the syntax every instruction may have some label this is optional field but BSF then you have to mention the file register which you want to deal and which bit of that particular file register. So definitely when you want to mention this F and B these are the two operands for this particular instruction. So F can take values from 0 to 127. So any file of selected bank will be a file register you can use for this particular instruction and which bit that file register will be of 8 bits. So which bit of that particular file register that will be decided by this B bit. Now what operation is carried out because of this instruction is this will set a particular bit B of file F. So this is the encoding this is how the opcode is created. So you change the file register based on opcode will be different. You change the bit location based on that opcode will be different. Now what operation is carried out because of this instruction bit B of file register F is set. So this is a single word single cycle instruction. No flag bits are affected because of execution of this particular instruction. Now talking about one example BSF. So what I am trying to do here flag register is the file register and bit number seven of that flag register I want to set. So before execution let us assume the contents of flag register are 0A. So this is representing 0A content and bit number seven if you look at bit number seven that bit number seven is clear here. But after execution of this particular instruction what you find is this bit number seven is set because of execution of this instruction. So only one bit gets changed hence the contents 0A will get changed to 8A after execution of this instruction. Now similarly we can have another instruction where after execution of this instruction it is going to clear a particular bit of a file register. Now BCF F comma B is the syntax the range of F and B is same. Then what is going to do it is going to clear the bit. So 0 is going to load it in the bit. Now no flags are affected again because of execution of this instruction this how encoding is done. Again it is a single word single cycle instruction. Now looking at the example you will find that BCF flag register seven. Now again assume that flag register seven this is the file register you are dealing with its most significant bit bit number seven is set before execution. Now if you execute this instruction BCF it is going to clear this particular bit. So after execution of this instruction what you find this bit is clear. So this is how this BCF instruction works. Now talking about next instruction bit test file and skip if clear. Now this is one bit oriented instruction which is going to test a particular bit of a particular file register which is specified in the instruction. So bit test skip if clear. Operants again file register taking range from 0 to 127 of a selected bank means you are selecting a particular bank any file register of that selected bank you can it can be F. Now B can be any bit of that particular file register what you are going to do operation is what skip. So what you are going to skip here you are going to skip execution of the next instruction which is written immediately after this. So skip if particular bit of file register F is equal to 0 next is instructions execution is going to be skipped. Now again no flags are affected this is how encoding is done and this is the description if B bit of register F is clear then the next instruction execution is skipped and if it is clear what exactly happens the next instruction which is already fetched during the current instruction execution that instruction is discarded instead of that a knob is executed. Now this will make this instruction two cycle instruction means if the condition is true if the bit is clear means condition is true in that case this will be a two cycle instruction if condition is false it will be a single cycle instruction itself and sequential execution will be carried out in that case automatically next instruction will get executed. Now talking about the example here you find that bit test file skip if clear flag you are testing which file register flag file register which bit bit number four. Now if it is clear then what you are going to do you are you are going to skip this particular execution next instructions execution is going to be skipped. Now look at this case number one where you find that before execution the contents of PC are addressed here means this is the next instruction the instruction whose label is here this is going to execute now flag bit is again zero which flag bit you are testing is bit number four is zero after execution of the instruction see what happens you are going to skip if the bit is clear so hence instead of executing the instruction whose label is false what will be PC contents contents of PC will be address of true means this next instruction will be skipped and after that whatever the new instruction is written that instruction gets executed. Now second case is before execution itself if the flag bit that bit number four of flag is one then what is going to happen in that case if that bit is one you want to skip the instruction when that bit is clear and bit is one so sequential execution so PC will be what address of false similar kind of instruction is available bit test file skip if set now when that particular bit of a particular file register is set for example again this encoding and this operation is quite similar only thing is you are going to skip the execution only if the bit is set so here take the example PC is pointing to address here means next instruction will be the execution of this particular instruction it is bit test file skip if set before execution if you are finding that the bit is zero itself so is it set no so if it is not set then you are not going to skip the execution of the next instruction so what instruction gets executed will be the immediate next instruction itself but if the bit number four is set if that particular bit is set then what happens what happens is you are going to be going to skip the execution of this instruction and which instruction is getting executed will be the instruction whose label is true so this is how the bit oriented instruction which is testing the particular bit of a particular file register works based on the condition if it is set or clear you are going to skip the execution of the next instruction these are the references used for this presentation thank you