Counters using the delay routine.

Discussion in 'Assembly Language Programming (ALP)' started by shabbir, Nov 17, 2006.

  1. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83

    Introduction



    I get lots of emails and PM to write some more Assembly language programs and as I have some time I thought of writing some more.

    Its called Counters using the delay routine.

    Subroutine



    The subroutine we will use is as follows. This will behave as a delay for our counter
    Code:
    //FUNC
       MVI C, FF
       // Load Register C with the Hex value FF
       DCR C
       // Decrement the C Register // Address of the statment is XXXX
       JNZ XXXX
       // loop till you get the counter reduced to zero
       RET
    
    Now we will write the actual program to have the counter
    Code:
       LXI SP, 87DD
       // Load immediate stack pointer
       LXI H, 0000
       // Load immediate register Pair H & L
       MVI B, 10
       // Load Register B with the Hex value 10
       SHLD 87FD
       // Store H & L direct
       PUSH B
       // Push register Pair B & C on stack
       CALL FUNC
       // Call the above subroutine
       POP B
       // Pop register Pair B & C off stack
       DCR B
       // Decrement B
       JNZ XXXX // - SHLD Location
       // Jump on no zero
       INX H
       // Increment H & L registers
       JMP XXXX // MVI B 10 location
       // Jump unconditional
    
    Now to make the decrement counter you just need one change INX to DCX
     
  2. bothie

    bothie New Member

    Joined:
    Nov 14, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    Harare,Zimbabwe
    wow! this seems to be too hard to understand , especially the delay part,is there another code of a counter where a delay is not implemented,if so pliz may you show us
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Just remove the CALL statement and that should be fine.
     
  4. bothie

    bothie New Member

    Joined:
    Nov 14, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    Harare,Zimbabwe
    so where really is the counting part,is it the same aspect as in c or c++ or its a different aspect all together i seem not to get it.
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Removing the CALL leaves you with the counter. specially the
    Code:
       DCR B
       // Decrement B
       JNZ XXXX // - SHLD Location
       // Jump on no zero
       INX H
       // Increment H & L registers
     
  6. bothie

    bothie New Member

    Joined:
    Nov 14, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    Harare,Zimbabwe
    so wat will happen wen we JNZ to SHLD ie what are we really doing on this location
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Looping till non zero by decrementing it.
     
  8. bothie

    bothie New Member

    Joined:
    Nov 14, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    Harare,Zimbabwe
    okay i get thanx
     
  9. sangelion

    sangelion New Member

    Joined:
    Feb 26, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    how to make delay counter with i/o.. like the problem.. the led will blink base on 4bit of switch.. i mean.. if 1111, the led will blink 15 times
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice