We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32
Dr Usman Ali, NUST College of E&ME
BRANCH, CALL, AND
TIME DELAY LOOP Chapter 3
Dr Usman Ali, NUST College of E&ME
Branch instructions and looping
Dr Usman Ali, NUST College of E&ME
Looping in microprocessors • Repeating a sequence of instructions or an operation a certain number of times • Commonly used instructions – DECFSZ – BNZ
Dr Usman Ali, NUST College of E&ME
DECFSZ instruction • decrement file Reg skip if zero • Format -- DECFSZ fileReg, d
Dr Usman Ali, NUST College of E&ME
DECFSZ instruction- example
Dr Usman Ali, NUST College of E&ME
BNZ instruction • branch if not zero • It branches (jumps) back to the target address referred to by the label
– GOTO, 32 bit, covers 1M memory space – BRA (branch), 16 bit, covers ±1K space Dr Usman Ali, NUST College of E&ME BZ example
Dr Usman Ali, NUST College of E&ME
Calculating the short branch address • All conditional branches such as BNC, BZ, and BNZ are short branches. • They are all 2-byte instructions. The first byte is the opcode and the second byte is the relative address. • The target address is relative to the value of the program counter. If the second byte is positive, then the jump is forward. If the second byte is negative, then the jump is backwards.
Dr Usman Ali, NUST College of E&ME
Unconditional jumps instructions structure
Dr Usman Ali, NUST College of E&ME
CALL INSTRUCTIONS AND STACK
Dr Usman Ali, NUST College of E&ME
CALL instructions • Used to call a subroutine – CALL, RCALL • Work with return instruction • 4 bytes, 2 bytes size
Dr Usman Ali, NUST College of E&ME
Stack and stack pointer • Stack is another 21-bit LIFO memory • Used by the CALL instructions to come back after execution of the called subroutine • Stack pointer register stores pointer to stack memory
Dr Usman Ali, NUST College of E&ME
Stack and stack pointer
Dr Usman Ali, NUST College of E&ME
Example- CALL instruction
Dr Usman Ali, NUST College of E&ME
Example- CALL instruction
Dr Usman Ali, NUST College of E&ME
Calling many subroutines from the main program
Dr Usman Ali, NUST College of E&ME
Program execution timings
Dr Usman Ali, NUST College of E&ME
Delay calculation • Two major factors – Crystal frequency – Microprocessor instruction execution cycles • Pipe-line vs non-pipelined architecture • Instruction size
Dr Usman Ali, NUST College of E&ME
Instruction cycle time for the PIC • One instruction/machine cycle corresponds to four periods of the clock • 2-bytes / 4-bytes instructions take 1/2 machine cycles • Branch instructions are exceptions
Dr Usman Ali, NUST College of E&ME Loop inside a loop
For the HERE loop, we have (5 x 250) 1 ~s = 1250 ~s. The AGAIN loop repeats the HERE loop 200 times; therefore, we have 200 x 1250 ~s = 250000 ~s, if we do not include the overhead