Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do some 8051 program ends with the code "LOOP: SJMP LOOP"

Tags:

assembly

8051

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.

like image 325
Sparkzz Avatar asked Apr 17 '17 20:04

Sparkzz


People also ask

What is SJMP in 8051?

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.

What is the meaning of 0000h?

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.

What is 0000h in microprocessor?

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.

How 8051 is programmed?

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.


1 Answers

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).

like image 99
old_timer Avatar answered Sep 20 '22 11:09

old_timer