"LOOP" routine in Assembly

Sep 23, 2009 3 Replies

=_NextPart_000_0047_01CA3C5F.D4A519F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable



Hi All



Google is NOT my friend here, or maybe I'm not searching correct - gets = gazillions of hits on examples which I don't understand



I have the below routine that work 100%, but I want to add a "LOOP" to = execute the FLASH routine i,e 5 times and then the FLASH_ODD routine 7 = times before calling "AJMP FLASH" again to start from the beginning. = Below is just a scale down version of my code, but If I can get this = resolved, I will be able to implement it in my code



#################################################



ORG 00H ; Starts Here FLASH: CPL P1.0 ; Turn on/off the LED P1.0 ACALL DELAY ; call one second delay AJMP FLASH_ODD ; jump to FLASH_ODD



FLASH_ODD: CPL P1.3 ; Turn on/off the LED P1.3 ACALL DELAY ; call one second delay AJMP FLASH ; jump to FLASH



DELAY: MOV R1,#0FFH REPEAT: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,REPEAT RET END=20



#################################################


Any suggestions will be greatly appreciated


=_NextPart_000_00B3_01CA3C5B.5FD956D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

begin: mov r3,#05 mov r4,#07

loop1: lcall flash djnz r3,loop1

Google is NOT my friend here, or maybe I'm not searching correct - = gets gazillions of hits on examples which I don't understand

I have the below routine that work 100%, but I want to add a "LOOP" to = execute the FLASH routine i,e 5 times and then the FLASH_ODD routine 7 = times before calling "AJMP FLASH" again to start from the beginning. = Below is just a scale down version of my code, but If I can get this = resolved, I will be able to implement it in my code

#################################################

ORG 00H ; Starts Here FLASH: CPL P1.0 ; Turn on/off the LED P1.0 ACALL DELAY ; call one second delay AJMP FLASH_ODD ; jump to FLASH_ODD

FLASH_ODD: CPL P1.3 ; Turn on/off the LED P1.3 ACALL DELAY ; call one second delay AJMP FLASH ; jump to FLASH

DELAY: MOV R1,#0FFH REPEAT: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,REPEAT RET END=20

#################################################

Any suggestions will be greatly appreciated

=_NextPart_000_0014_01CA3C66.5061D500 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

loop1: lcall flash djnz r3,loop1

Google is NOT my friend here, or maybe I'm not searching correct - = gets gazillions of hits on examples which I don't understand

I have the below routine that work 100%, but I want to add a "LOOP" = to execute the FLASH routine i,e 5 times and then the FLASH_ODD routine =

7 times before calling "AJMP FLASH" again to start from the beginning. = Below is just a scale down version of my code, but If I can get this = resolved, I will be able to implement it in my code

#################################################

ORG 00H ; Starts Here FLASH: CPL P1.0 ; Turn on/off the LED P1.0 ACALL DELAY ; call one second delay AJMP FLASH_ODD ; jump to FLASH_ODD

FLASH_ODD: CPL P1.3 ; Turn on/off the LED P1.3 ACALL DELAY ; call one second delay AJMP FLASH ; jump to FLASH

DELAY: MOV R1,#0FFH REPEAT: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,REPEAT RET END=20

#################################################

Any suggestions will be greatly appreciated

=_NextPart_000_000E_01CA437C.575E3D40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

HI All

At first I thought this is working , but when I added a huge delay to = closely monitor the ports I notice that it ignores the repeat intervals, = and after doing each of them sequentialy, it starts doing the routines = randomly. Any suggestion why this will happen: It seems to ignore the = results after the "MOV r?," commands , and do every LOOP? only once, and = then after completing them once, starts to do them in random order

ORG 00H ; Execution Starts Here

BEGIN: MOV r3,#2=20 MOV r4,#2 MOV r5,#2 MOV r6,#2 MOV r7,#3 =20 LOOP1: LCALL ENGINE_1 DJNZ r3,LOOP1 =20 LOOP2: LCALL EVENT_2 DJNZ r4,LOOP2 =20 LOOP3: LCALL EVENT_3 DJNZ r5,LOOP3 =20 LOOP4: LCALL CLEAR_CHECK_1 DJNZ r6,LOOP4 =20 LOOP5: LCALL RESULT_PULSE_1 DJNZ r7,LOOP5 LJMP BEGIN

....... CODE

loop1: lcall flash djnz r3,loop1

loop2: lcall flash_odd djnz r4,loop2 ljmp begin

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required