Search code examples
assemblymicrocontroller8051

Unable to declare Procedure in 8051 Assembly programming language


I want to work with 8051 Procedure. What i want to do is to declare a procedure for delay and use it for led blinking. I'm using Keil uVision3 to write my code. I have googled a lot but did not find any help. Below is the the sample code of my program.

ORG 00h

MOV P0, #00h
MOV P1, #00h
MOV P2, #00h
MOV P3, #00h

CALL DELAY PROC     ;calling delay procedure to produce some delay.


DELAY PROC           ;procedure implementation starts here for generating some delay

    MOV R0, #255

    NOW:
    DJNE R0, 0 , HERE

    MOV R1, #255

    HERE: 
    DJNE R1, 0, NOW

    RET
    ENDP


END

This code gives some syntax errors. What is the correct syntax to declare a procedure and how to use it. Please guide me, what is wrong with my code and please make me correct. I would be thankful to you.


Solution

  • For the plain 8051 chips, you don't even have to bother by declaring procedures - just give them a label and call them. Such as:

        ACALL delay
        ; ... main progam continues here
        ; make sure you don't fall through into your procedure!
    
    delay:
        ; ... procedure code here ...
        RET
    

    If you do want to declare your procedure, according to the keil manual you have to do something like this:

        CALL delay
        ; ... main progam continues here
        ; make sure you don't fall through into your procedure!
    
    delay PROC
        ; ... procedure code here ...
        RET
    delay ENDP