assembly instruction

Discussion in 'Embedded Systems and Microcontrollers' started by abhimanyu143, Jan 20, 2015.

  1. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    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 (Text):
    1.        ORG     0
    2.  
    3. MainLoop:
    4.         setb    P1.0                    ; Turn LED ON
    5.         Acall   Delay                   ; Wait a short time
    6.         clr     P1.0                    ; Turn LED OFF
    7.         Acall   Delay                   ; Wait a short time
    8.           sjmp  MainLoop                ; Loop forever
    9.  
    10. Delay:
    11.         mov     R1,#90                  ; Set up outer loop count
    12.         mov     R2,#225                   ; Set up inner loop count
    13. Delay1: djnz    R2,Delay1               ; Inner loop
    14.         djnz    R1,Delay1               ; Outer loop
    15.         ret
    16.  
    17.         end
    I don't understand how does following instruction fetch , decode and execute ?
    Code (Text):
    1.  MainLoop:
    2. Acall  Delay
    3. sjmp  MainLoop
    how these instructions work with 8051 controller ?
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    CALL and JMP instructions work in same way on all microcontrollers (or almost all).
    What part of the instruction do you not understand?
     
  3. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    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 ?
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    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.
     
  5. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    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 ?
     
    Last edited: Jan 20, 2015
  6. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    Because you told it to JMP.

    Code (Text):
    1.  
    2. main:
    3.    :
    4.    :
    5.   JMP here
    6.    :
    7.    :
    8.  
    9. here:
    10.    :
    11.    more code
    12.    :
    13.  
    You told it JMP

    You gave it the destination here
     
    abhimanyu143 likes this.
  7. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    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
     
  8. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    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.
     
  9. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    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.
     
  10. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    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.
     
Loading...