Counters using the delay routine.

shabbir's Avatar author of Counters using the delay routine.
This is an article on Counters using the delay routine. in Assembly Language Programming (ALP) Tutorials.
Rated 5.00 By 2 users

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
bothie's Avatar
Go4Expert Member
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
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Just remove the CALL statement and that should be fine.
bothie's Avatar
Go4Expert Member
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.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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
bothie's Avatar
Go4Expert Member
so wat will happen wen we JNZ to SHLD ie what are we really doing on this location
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Looping till non zero by decrementing it.
bothie's Avatar
Go4Expert Member
okay i get thanx
sangelion's Avatar, Join Date: Feb 2008
Newbie Member
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