Almost all the simple 8051 programs I have seen so far ends with the code
LOOP: SJMP LOOP
.
From my understanding I think the above instruction creates an infinite loop by calling the same instruction again and again. But what is the purpose of having infinite loop at the end of a program and if it keeps running again and again then when does the program gets terminated.
The SJMP instruction transfers execution to the specified address. The address is calculated by adding the signed relative offset in the second byte of the instruction to the address of the following instruction.
0000h is the starting address location of first instruction of your program if you specify 0000 h . You can use any address(0000h - 0FFFh) in the place of the 0000h. Eg: org 0000h. Mov ax,02h.
The 8051 Microcontroller Assembly Language Program will start assembling from the Program Memory Address 0000H. This is also the address from which the 8051 Microcontroller will start executing the code.
Use Keil to write programs for 8051 Microcontroller We are selecting Microchip, and then by expanding we are selecting AT89C51 device and click ok. Now go to the New in the menu and select New. It will open a new editor to write code.
How else do you "terminate" or end a bare metal program? There generally is no halt or other command, the processor doesnt stop. The safest/cleanest is to have it infinite loop (as opposed to just wandering through memory trying to execute what it finds).
so for simple educational processor/microcontroller programs, programs that "end", you would want to end them in an infinite loop if the processor doesnt have a halt. Most mcus never halt they run whatever forever (they might go to sleep in a low power state, but then wake up when you press a button on the remote or whatever).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With