1 / 13

PI18… Ch. 3.1

PI18… Ch. 3.1. Md. Atiqur Rahman Ahad http://aa.binbd.com. 3.1 Branch - Loop. 2 ways to loop in PIC. DECFSZ  decrement fileReg ,  skip next instruction if 0 DEC F SZ fileReg , d Place GOTO target right below it to create a loop. AGAINX ADDLW 3 | | DECFSZ COUNTX

john
Download Presentation

PI18… Ch. 3.1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PI18…Ch. 3.1 Md. Atiqur Rahman Ahad http://aa.binbd.com

  2. 3.1 Branch - Loop • 2 ways to loop in PIC. • DECFSZ  decrement fileReg,  skip next instruction if 0 DECFSZ fileReg, d • Place GOTO target right below it to create a loop

  3. AGAINX ADDLW 3 | | DECFSZ COUNTX GOTOAGAINX

  4. Do Exa. 3.1 Add 3 to WREG – ten times. Place the result in SFR of PORTB.

  5. COUNTX EQU 0x25 ; Use location 25h for counter COUNTX MOVLW d’10’; WREG=10 [d=decimal] for counter MOVWF COUNTX; count, COUNTX = 10 MOVLW 0 ;clear WREG to 0. WREG = 0 now AGAINX ADDLW 3 ;sum, WREG = 3, then added up… DECFSZ COUNTX, F ;F, not W. If ‘W’, value to WREG GOTOAGAINX;repeat – until COUNTX becomes 0 MOVWF PORTB ;send sum/result to PORTB SFR

  6. 2 ways to loop in PIC. • DECFSZ • BNZ - branch if not zero - from PIC18… PIC16 has no BNZ

  7. AGAINX ADDLW 3 ;sum, WREG = 3, then added up… DECFSZ COUNTX, F ;F, not W. If ‘W’, value to WREG GOTOAGAINX;repeat – until COUNTX becomes 0 AGAINX ADDLW 3;sum, WREG = 3, then added up… DECF COUNTX, F ;decrement counter ; decrement fileReg. Z=1 [zero flag] if fileReg = 0 BNZAGAINX;branch/jump to AGAINX if Z=0

  8. Q. What is the max. number of times that the loop in Exa. 3.1/3.2 can be repeated?  Location COUNTX in fileRegis an 8-bit register. • It can hold max. of FFh / 1111 1111b / 255 decimal • So, it can be repeated max. of 255 times.

  9. Q. How to repeat 255++ times? Think about C prog. for (…){ … for (…){ … } } • Nestedloop of 2/3/… times. • ENDLESS? Time cost or complexity [of ur algorithm] . • O(n2), O(nlogn), O(n3), …

  10. Read other conditional jumps • BC - branch if C=1 • BNC … if no carry, / C=0 • BZ …if Z= 1 • BNZ • Etc. …

  11. All conditional jumps are short jumps • The address of the target must be within 256 bytes of the contents of the program counter (PC). • Read – unconditional long jumps • GOTO • Branch

  12. Function / subroutine • CALL - long call • RECALL - relative call • What is User-definedfunction? [think C prog] • Why do we use User-defined function?

  13. Stack – LIFO? FIFO? • Pop / Push Instructions … … CALL UserDefinedFunction;call of a subroutine Instructions … ------------------------------------------------------------- UserDefinedFunctionInstruction ;start of the subroutine Instruction … RETURN ;finishof the subroutine ;return to caller

More Related