Personally, I like using nested loops to save on program memory when creating delays. I never create delays with just the nop(no operation op-code). Macro's are great, but not great for saving on program memory as the assembler really just rewrites the code content in the macro wherever the macro is used in the main code. Code gets bulky, and for bigger projects, this could be too bulky. It would be easier to place the content of the macro into a subroutine, and then just call that subroutine whenever you need it. However, great video, I don't often see any assembly for microchip. Just the current craze over Arduino, which I loved until I discovered PICs.
Of course you can! What is the crystal frequency? You can create a 1 second delay subroutine and call the subroutine 3 times. That makes 3 seconds delay. You can call it n times and you've successfully created n seconds delay!
so a sub routine and a time delay are the same thing? for example, if im asked to create a subroutine of 1ms, is it the same as creating a time delay of 1ms?
Best Mhike A subroutine is a group of instructions grouped together under a name. Each time you call the name of the subroutine, you are actually executing the group of instructions. For example, i have a subroutine and I name the subroutine as "Take a bath". So this subroutine is actually composed of several instructions or steps. For example step 1 get towel, step 2 get soap, step 3 walk to bathroom, step 4 start washing. whenever i need to perform the 4 steps of taking a bath again and again in my program. what i can do is just call the subroutine name Take a bath and the computer will execute the 4 steps defined under the subroutine
so in the above case, my subroutine consist of instructions to create time delay. Whenever i need the time delay to happen in my program, i'd just call the subroutine name.
ok so i have this assignment that is due tomorrow, it says i should create a 1 milisecond subroutine using assembly language. how do i go about it? thanks for the early replies man much appreciated
Using " nop delays" is a waste a CPU. Start a timer and let your code do other work til the interrupt for the timer happens. Using " nop delays" is not an effienct way to write code because your code is doing nothing but calling the same instruction over and over, If you are using delays to blink a led, why not set a timer with interrupt? Turn led off and start timer, continue checking sensor, storing data etc etc, once the timer interrupt triggers turn led back on. Never use " nop delays" professionally.