assembly instruction

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
hello ,
i need help to understand how does each instruction fetch decode and execute in 8051 microcontroller
I made small project for LED blinking on proteus software

circuit :
upload_2015-1-21_7-51-31.png

assembly code :
Code:
       ORG     0

MainLoop:
        setb    P1.0                    ; Turn LED ON
        Acall   Delay                   ; Wait a short time
        clr     P1.0                    ; Turn LED OFF
        Acall   Delay                   ; Wait a short time
          sjmp  MainLoop                ; Loop forever

Delay:
        mov     R1,#90                  ; Set up outer loop count
        mov     R2,#225                   ; Set up inner loop count
Delay1: djnz    R2,Delay1               ; Inner loop
        djnz    R1,Delay1               ; Outer loop
        ret

        end
I don't understand how does following instruction fetch , decode and execute ?
Code:
 MainLoop:
Acall  Delay
sjmp  MainLoop
how these instructions work with 8051 controller ?
 

MrChips

Joined Oct 2, 2009
30,618
CALL and JMP instructions work in same way on all microcontrollers (or almost all).
What part of the instruction do you not understand?
 

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
CALL and JMP instructions work in same way on all microcontrollers (or almost all).
What part of the instruction do you not understand?
I looked this link http://www.keil.com/support/man/docs/is51/is51_sjmp.htm
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 instructoin to the address of the following instruction. The range of destination addresses is from 128 before thenext instruction to 127 bytes after the next instruction.

Operation
SJMP
PC = PC + 2
PC = PC + offset

how does PC load with new address ? what is offset ?
 

MrChips

Joined Oct 2, 2009
30,618
In this particular example, offset is a signed byte, -128 to +127.

It is the distance (number of bytes) between the current instruction and the destination.
Since this instruction will occupy two bytes, that is, the opcode and the offset, the offset is adjusted by 2.

This instruction is also known as a relative branch or relative jump instruction.
 

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
In this particular example, offset is a signed byte, -128 to +127.

It is the distance (number of bytes) between the current instruction and the destination.
Since this instruction will occupy two bytes, that is, the opcode and the offset, the offset is adjusted by 2.


This instruction is also known as a relative branch or relative jump instruction.
that's the point , I don't understand. If possible can you tell me with block diagram
basic block diagram
Operation
SJMP
PC = PC + 2
PC = PC + offset
upload_2015-1-21_11-40-48.png
I just want to understand basic architecture of Jump instruction (hardware ). how does PC know that PC need to jump at address ?
which component we need to add with PC to load new address ?
 

Attachments

Last edited:

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
Because you told it to JMP.

Code:
main:
   :
   :
  JMP here
   :
   :

here:
   :
   more code
   :
You told it JMP

You gave it the destination here
that's about code. I am trying to understand basic architecture of Jump instruction.

architecture of Jump instruction
I want to implement small block diagram for Jump instruction

Q1 how to make architecture for jump instruction ?
hint (asking for small part for basic understanding )
Q2. what I need ?
ans. I need PC and multiplexer.I think ,I have to add extra circuitry
Q3 what is offset ?
I am not clear what is offset and how to make offset
 

MrChips

Joined Oct 2, 2009
30,618
Your processor will encounter two bytes, 80 XX

80 is the opcode for SJMP
XX is the signed byte offset

The processor will add XX to the PC and replace the result into the PC.
 

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
Your processor will encounter two bytes, 80 XX

80 is the opcode for SJMP
XX is the signed byte offset

The processor will add XX to the PC and replace the result into the PC.
I found this wikki page wikibooks.org/wiki/Microprocessor_Design/Program_Counter
there are diagram for jump and branch instruction. I don't understand why there are different multiplexer for jump and branch instructions. Please help me to understand that page on Program counter design.
 

MrChips

Joined Oct 2, 2009
30,618
I would ignore what you see in those diagrams. The purpose of the diagram is to show graphically what needs to be done in order to reload the PC.

What you need to do is ADD the OFFSET to the PC. That is the purpose of the box labelled ALU.

In normal instruction sequence, you want to increment the PC with the instruction byte count. So that calls for another ALU.

Then you need to choose between the two results. Is it a normal sequence or is it a JMP instruction? So you use a MUX to make the selection.

There are more ways to design a processor.
 
Top