Back the first decfsz instruction will execute for

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: decfsz instruction will execute for 256 times. DELAY_L will become 0 after the 256th decrement. The bra line will be skipped. bra DELAY_H will be decremented to 1. Not zero. Branch DELAY_H back to the start. back The first decfsz instruction will execute for 256 times. DELAY_H will be decremented to 0. End program. In total, the first decfsz instruction executes 2x256 In 36 times. times. Using Program Loops to Create Time Delays Using • Suppose DELAY_L = 0 and DELAY_H = 2. DelayLoop: DelayLoop: decfsz DELAY_L bra DelayLoop decfsz DELAY_H bra DelayLoop 1 instruction cycle (2 if skip) 2 instruction cycles 1 instruction cycle (2 if skip) 2 instruction cycles • The first two lines will run for 256 times, lasting The 255*3+2 = 767 instruction cycles during each loop. • The last two lines will run for 2 times, lasting 3+2 = 5 The instruction cycles. instruction • There are 2 loops (set by DELAY_H). There • The whole delay loop will run for 767*2+5 = 1539 The instruction cycles. instruction • If clock frequency = 4MHz (instruction freq. = 1MHz), If 37 the whole loop lasts 1.539 msec. the 4. Subroutine and Stack 4. 38 Subroutine Subroutine • A subroutine is a sequence • e.g., Lab 1 subroutine of instructions that can be called from different places in a program. in • Two reasons for creating Two subroutines: subroutines: – The problem is too big: Easier The to divide the problem into smaller sub-problems – There are several places in a There program that need to perform the same operation. the 39 Subroutine Subroutine • Subroutine is similar to branching. The Subroutine difference is that PIC needs to return to the main program where the subroutine was called. was...
View Full Document

Ask a homework question - tutors are online