![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Dear all, when shd i use a "call" and a "goto"? what is the diff? In what cases shd we use them correctly? Thanks | |
| |
| | #2 |
|
I think the only difference is that "call" loads the return address right when you call it and then goes to the address, while "goto" simply goes to the address.
| |
| |
| | #3 |
|
Yes, Call is used to CALL subroutines, which are ended with RETURN instruction. GOTO will just change PC address and the program will jump to the label you are calling with no return.
__________________ "I share, thus I am" Jay.slovak Read this! ICD2 Clone Best PIC/DsPIC Bootloader Read my Inchworm ICD2 review! | |
| |
| | #4 |
|
"goto" is stupid command. Use "call" instead. This is required fron the "good practice" in programming.
| |
| |
| | #5 | |
| Quote:
But certainly using CALL is important as well, structuring your program as subroutines is very good practice and allows you to reuse many of the subroutines in other programs. As for the high level languages, their compilers will certainly generate plenty of GOTO instructions, regardless of the processor used. | ||
| |
| | #6 |
|
In C every if/else and case statement generates a goto (jump) assembly instruction. In case statements the break statement coresponds to a jump/goto instruction. Function calls generate a Call instruction. The goto instruction is used to direct the flow of the program. The CALL instruction is used to build sections of code that will get used in more than one place in the code. | |
| |
| | #7 |
|
In general, call should be used when performing operations on a set of data, polling inputs, sending a structured set of output data, or performing a routine that controls peripherals. In general, goto should be used to return to the top of a loop and to conditionally skip over sections of code. Each instruction holds 11 bits of the address. When you use call this adress is pushed onto the stack. Remeber it is only 8 words deep so be careful when calling within functions. There must be a return opcode after every subroutine that is called or else the stack will likely overflow. These are just general guidlines and actual use will vary depending on how your program is structured, but this should give you a basic idea.
| |
| |
| | #8 | |
| Quote:
Code: XORLW 0x32
BTFSS STATUS , Z
GOTO Label_0027
GOTO Label_0029
Label_0029 GOTO Duration_32
Label_0027 GOTO Label_002B
Label_002B GOTO Try_Dur_16
Duration_32 MOVLW 0x20
| ||
| |
| | #9 | |
| Quote:
| ||
| |
| | #10 | ||
| Quote:
| |||
| |
| | #11 |
|
oh so you are working on that ringtone generator which is based on a 16F877 are you going to write a tutorial about this or not???? | |
| |
| | #12 | |
| Quote:
| ||
| |
| | #13 |
|
Following on from the horrible row of goto's in the HEX file I disassembled, I've downloaded the free limited version of the Hi-Tech compiler - PICC Lite. So I've been doing some experiments with it - if you set 'full optimisation' ON during the compiling process it doesn't produce the nasty multiple goto's. The entire code ends up considerably smaller as well - makes you wonder why all the C generated HEX files I've ever looked at haven't been generated like that?. I've also compiled the ringtone software for both 18 pin (16F627) and 8 pin (12F629/12F675) - with just very minor changes. This gives a rather useful little 8 pin chip which can play a Nokia monophonic ringtone when you apply power to it! - could make an interesting audible alarm?. | |
| |
| | #14 |
|
Turning off the optimisations can make it easier to debug code. Compiler optimisations will also remove software delay loops and rearange sections of code that can make optimising a bit confusing for beginers. Also be careful to use the volatile keyword when nessesary - one of my professors in school spent 4-5 hours trying to debug code that was being optimised out because he forgot to make a variable volatile. The down side to turning off the optimiser is that the compiler generates really bone-headed code.
| |
| |
| | #15 | |
| Quote:
| ||
| |
|
| Tags |
| call, goto, shd |
| Thread Tools | |
| Display Modes | |
| |