Q.Sample of Assembly Language Program: explain the following 8051 assembly language program, which loads two numbers and accumulates them (with 10H) in the accumulator.
ORG OH ; start (origin) at location 0
MOV R2, #15H ; load 15H into R2
MOV R6, #23H ; load 23H into R6
MOV A, #0 ; load 0 into A
ADD A, R2 ; add contents of R2 to A ; now A = A + R2
ADD A, R6 ; add contents of R6 to A ; now A = A + R6
ADD A, #10H ; add to A value 10H ; now A = A + 10H
HERE: SJMP HERE ; stay in this loop
END ; end of ASM source file
ORG OH ; start (origin) at location 0
MOV R2, #15H ; load 15H into R2
MOV R6, #23H ; load 23H into R6
MOV A, #0 ; load 0 into A
ADD A, R2 ; add contents of R2 to A ; now A = A + R2
ADD A, R6 ; add contents of R6 to A ; now A = A + R6
ADD A, #10H ; add to A value 10H ; now A = A + 10H
HERE: SJMP HERE ; stay in this loop
END ; end of ASM source file
[!TLDR]
The program initialises A to 0 and adds 15H, 23H and 10H to it, leaving A = 48H, then loops in place.
Concept - directives vs instructions. An assembly program mixes instructions (MOV, ADD, SJMP - commands executed by the CPU) with directives (ORG, END - directions to the assembler, not the CPU). ORG 0H tells the assembler to place the following code starting at program-memory address 0; END marks the end of the source file.
Line-by-line:
MOV R2, #15H- load 15H into R2.MOV R6, #23H- load 23H into R6.MOV A, #0- clear the accumulator, A = 0.ADD A, R2- A = 0 + 15H = 15H.ADD A, R6- A = 15H + 23H = 38H.ADD A, #10H- A = 38H + 10H = 48H.HERE: SJMP HERE- an unconditional short jump to its own label, holding the processor in an infinite loop so it does not run past the program.
Result: 15H + 23H + 10H = 21 + 35 + 16 = 72 decimal = 48H.
[!ANSWER]
A = 48H (72 decimal); the program then stays in the loop HERE: SJMP HERE.
[!NOTE]
The textbook typesets the hexadecimal digit 0 (zero) as the capital letter "O" - the first line prints as "ORG OH", but the correct 8051 directive is ORG 0H.
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.