Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Tutorials (http://www.go4expert.com/articles/assembly-language-programming/)
-   -   Counters using the delay routine. (http://www.go4expert.com/articles/counters-using-delay-routine-t1926/)

shabbir 17Nov2006 21:48

Counters using the delay routine.
 

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 21Nov2006 14:22

Re: Counters using the delay routine.
 
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 21Nov2006 15:18

Re: Counters using the delay routine.
 
Just remove the CALL statement and that should be fine.

bothie 21Nov2006 15:39

Re: Counters using the delay routine.
 
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 21Nov2006 16:21

Re: Counters using the delay routine.
 
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 21Nov2006 17:57

Re: Counters using the delay routine.
 
so wat will happen wen we JNZ to SHLD ie what are we really doing on this location

shabbir 21Nov2006 18:22

Re: Counters using the delay routine.
 
Looping till non zero by decrementing it.

bothie 21Nov2006 18:28

Re: Counters using the delay routine.
 
okay i get thanx

sangelion 27Feb2008 05:04

Re: Counters using the delay routine.
 
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


All times are GMT +5.5. The time now is 11:54.