You are on page 1of 25

DrUsmanAli,NUSTCollegeofE&ME

BRANCH,CALL,AND
TIMEDELAYLOOP
Chapter3

DrUsmanAli,NUSTCollegeofE&ME

Branch instructions and looping


Branchinstructionsandlooping

DrUsmanAli,NUSTCollegeofE&ME

Looping in microprocessors
Loopinginmicroprocessors
Repeating
Repeatingasequenceofinstructionsoran
a sequence of instructions or an
operationacertainnumberoftimes
Commonlyusedinstructions
Commonly used instructions
DECFSZ
BNZ

DrUsmanAli,NUSTCollegeofE&ME

DECFSZ instruction
DECFSZinstruction
decrementfileRegskipzero
decrement file Reg skip zero
Format DECFSZfileReg,d

DrUsmanAli,NUSTCollegeofE&ME

DECFSZ instruction example


DECFSZinstruction

DrUsmanAli,NUSTCollegeofE&ME

BNZ instruction
BNZinstruction
branch
branchifnotzero
if not zero
Itbranches(jumps)backtothetargetaddress
referred to by the label
referredtobythelabel

DrUsmanAli,NUSTCollegeofE&ME

BNZ instruction example


BNZinstruction

DrUsmanAli,NUSTCollegeofE&ME

Nestedloop

DrUsmanAli,NUSTCollegeofE&ME

Nestedloop

DrUsmanAli,NUSTCollegeofE&ME

Conditional/unconditionalshort/long
jumps
Short,conditionaljumps
Short, conditional jumps

Long,unconditionaljumps
GOTO,32bit,covers1Mmemoryspace
BRA(branch),16bit,covers1Kspace
DrUsmanAli,NUSTCollegeofE&ME

Instructionsstructure

DrUsmanAli,NUSTCollegeofE&ME

CALL INSTRUCTIONS AND STACK


CALLINSTRUCTIONSANDSTACK

DrUsmanAli,NUSTCollegeofE&ME

CALLinstructions
Usedtocallasubroutine
CALL,RCALL

Workwithreturninstruction
4bytes,2bytessize
4 bytes, 2 bytes size

DrUsmanAli,NUSTCollegeofE&ME

Stack and stack pointer


Stackandstackpointer
Stack
Stackisanother21
is another 21bit
bitLIFOmemory
LIFO memory
UsedbytheCALLinstructionstocomeback
after execution of the called subroutine
afterexecutionofthecalledsubroutine
Stackpointerregisterstorespointertostack
memory

DrUsmanAli,NUSTCollegeofE&ME

Stack and stack pointer


Stackandstackpointer

DrUsmanAli,NUSTCollegeofE&ME

Example CALLinstruction

DrUsmanAli,NUSTCollegeofE&ME

Example CALLinstruction

DrUsmanAli,NUSTCollegeofE&ME

Program execution timings


Programexecutiontimings

DrUsmanAli,NUSTCollegeofE&ME

Delay calculation
Delaycalculation
Twomajorfactors
Two major factors
Crystalfrequency
Microprocessorinstructionexecutioncycles
Microprocessor instruction execution cycles
Pipelinevs nonpipelinedarchitecture
Instruction size
Instructionsize

DrUsmanAli,NUSTCollegeofE&ME

Pipelining

DrUsmanAli,NUSTCollegeofE&ME

Instruction cycle time for the PIC


InstructioncycletimeforthePIC
One
Oneinstructioncyclecorrespondstofour
instruction cycle corresponds to four
periodsoftheclock
2bytes/4bytesinstructionstake1/2
2 bytes / 4 bytes instructions take 1/2
machinecycles
Branchinstructionsareexceptions
B
hi
i
i

DrUsmanAli,NUSTCollegeofE&ME

Appendix A
Appendix
A

DrUsmanAli,NUSTCollegeofE&ME

Example instructionsexecutiondelays
Example
instructions execution delays

DrUsmanAli,NUSTCollegeofE&ME

Example subroutineexecutiondelay
Example
subroutine execution delay
Crystalfreq.=4MHz
Crystal freq = 4MHz

DrUsmanAli,NUSTCollegeofE&ME

You might also like