Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/20/10 14:51
Read: times


 
#173357 - document what happens to ACC.
Responding to: ???'s previous message
Writing ASM code is a lot more finicky than using a High Level Language.

So it is wise to document:
1. what you pass to a function
2. what is returned by the function
3. what the function actually performs
4. what side-effects are there. e.g. is ACC or other Registers altered

Only you know what your delay function does.

Trace the program flow with a pencil and paper. It looks as if you may execute SUB2, but when you come back you may start doing SUB3 or SUB4.

You may possibly want to:

      CJNE A,#'1',NOT1
      AJMP SUB1            ;go do this but not come back here
NOT1: CJNE A,#'2',NOT1
      AJMP SUB2            ;go do this but not come back here
NOT2: 

 


I also note that you are writing a bit high to turn on a transistor.
As a general rule, 8051's use active-low logic. Most 8051's cannot source current only sink current.

You may also notice that you have 'similar' code. If you can re-use code, it only needs debugging once.


      CJNE A,#'1',NOT1
      MOV  A,#(1<<0)
      AJMP SUBX            ;go do this but not come back here
NOT1: CJNE A,#'2',NOT1
      MOV  A,#(1<<1)
      AJMP SUBX            ;go do this but not come back here
NOT2: 

...

; pass bit mask in ACC
; possibly destroy ACC
; 
SUBX:                  
      MOV P2, A            ;TURN ON PORT2 with masc in ACC
      ACALL DELAY
      MOV P2, #00h
      RET

 


David.



List of 16 messages in thread
TopicAuthorDate
Question on asm code            01/01/70 00:00      
   2 things            01/01/70 00:00      
   some change            01/01/70 00:00      
      even simpler            01/01/70 00:00      
         thanks for the simplified            01/01/70 00:00      
            yes, and even simpler            01/01/70 00:00      
               code and comments            01/01/70 00:00      
                  ;; ??            01/01/70 00:00      
                     thanks for the explanation            01/01/70 00:00      
   Short?            01/01/70 00:00      
      need some helps            01/01/70 00:00      
         Your circuit should work            01/01/70 00:00      
            Getting Rid Of Power On Relay Energize            01/01/70 00:00      
               Thank You All            01/01/70 00:00      
   document what happens to ACC.            01/01/70 00:00      
      noticed and questions            01/01/70 00:00      

Back to Subject List