This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DELAY FUNCTION IS NOT RETURNED

Hello everyone.
I'm beginner for ASM programming.
I tried programming by using modular programming method in ASM.
I built 2 modules (seperately): delay_s.a and main.a.
delay_s.a:

;===========================================================================
;Description:
;
;               - in: delay_s_i
;               - out: non
;===========================================================================
;===========================================================================
                                        PUBLIC                  delay_s_i, delay_s
;===========================================================================
;===========================================================================
?DT?delay                       SEGMENT                 DATA
                                        RSEG                    ?DT?delay

delay_s_i:                      DS                              1                       ;reserve 1 byte
;===========================================================================
;===========================================================================
?PR?delay                       SEGMENT                 CODE
                                        RSEG                    ?PR?delay
delay_s:
                                        MOV                             A, delay_s_i
                                        MOV                             B, #14          ;to delay approximately 1s - don't care about it
                                        MUL                             AB                      ;
                                        MOV                             delay_s_i, A
                                        MOV                             A, #0
                                        SETB                    TR0
loop1:                          JNB                             TF0, $
                                        CLR                             TF0
                                        DEC                             delay_s_i
                                        CJNE                    A, delay_s_i, loop1
                                        RET
;============================================================================
;============================================================================
                                        END
;============================================================================


main.a:

extrn code (delay_s)
extrn data      (delay_s_i)
org 0000h
mov sp, #7fh
main:
clr p2.0
mov     delay_s_i, #1
call delay_s
setb    p2.0
mov     delay_s_i, #1
call delay_s
jmp main
end


Compiling is ok.
I used the debug tool to test and i realized that the delay function is not returned to main function. I don't know why.
I need some help please.
Thank you

Parents
  • Thanks for your reply.
    I checked my program again, and I realized that i forgot to config Timer 0 in 16 bit mode. (MOV TMOD, #00000001b) in main function. And I run debug again, but the program still doesn't work.
    I expose here two modules (delay.a and main.a) again.
    main.a

    extrn code (delay_s)
    extrn data      (delay_s_i)
    org 0000h
    jmp     start
    org 0050h
    start:
    mov sp, #7fh
    mov     TMOD, #00000001b ; Timer 0 - 16bit mode
    main:
    clr p2.0
    mov     delay_s_i, #1
    call delay_s
    setb    p2.0
    mov     delay_s_i, #1
    call delay_s
    jmp main
    end
    

    delay_s.a

    ;===========================================================================
    ;Description:
    ;               - delay for approximately 1 s
    ;               - in: delay_s_i
    ;               - out: non
    
    
                                            PUBLIC                  delay_s_i, delay_s
    ;=====================================================
    ?DT?delay                       SEGMENT                 DATA
    RSEG                    ?DT?delay
    delay_s_i:      DS      1
    ;=====================================================
    ?PR?delay                       SEGMENT                 CODE
    RSEG                    ?PR?delay
    delay_s:
    MOV                             A, delay_s_i
    MOV                             B, #14
    MUL                             AB
    MOV                             delay_s_i, A
    MOV                             A, #0
    SETB                    TR0
    loop1:                          JNB                             TF0, $
    CLR                             TF0
    DEC                             delay_s_i
    CJNE                    A, delay_s_i, loop1
    RET
    END
    
    


    Running debug again, when encounter the

     call delay_s
    

    in main function, there's an error in debug window, it's "error 65: access violation at I:0x81: no 'write' permission.; it means the address of next instruction was not pushed into stack and I think this causes the problem. When encounter

     RET
    

    , there's no value popped out of stack (and 0 value popped out instead), and the program restart at 0000h, not be returned to where it was called.

    Thanks and wait for your answers.

Reply
  • Thanks for your reply.
    I checked my program again, and I realized that i forgot to config Timer 0 in 16 bit mode. (MOV TMOD, #00000001b) in main function. And I run debug again, but the program still doesn't work.
    I expose here two modules (delay.a and main.a) again.
    main.a

    extrn code (delay_s)
    extrn data      (delay_s_i)
    org 0000h
    jmp     start
    org 0050h
    start:
    mov sp, #7fh
    mov     TMOD, #00000001b ; Timer 0 - 16bit mode
    main:
    clr p2.0
    mov     delay_s_i, #1
    call delay_s
    setb    p2.0
    mov     delay_s_i, #1
    call delay_s
    jmp main
    end
    

    delay_s.a

    ;===========================================================================
    ;Description:
    ;               - delay for approximately 1 s
    ;               - in: delay_s_i
    ;               - out: non
    
    
                                            PUBLIC                  delay_s_i, delay_s
    ;=====================================================
    ?DT?delay                       SEGMENT                 DATA
    RSEG                    ?DT?delay
    delay_s_i:      DS      1
    ;=====================================================
    ?PR?delay                       SEGMENT                 CODE
    RSEG                    ?PR?delay
    delay_s:
    MOV                             A, delay_s_i
    MOV                             B, #14
    MUL                             AB
    MOV                             delay_s_i, A
    MOV                             A, #0
    SETB                    TR0
    loop1:                          JNB                             TF0, $
    CLR                             TF0
    DEC                             delay_s_i
    CJNE                    A, delay_s_i, loop1
    RET
    END
    
    


    Running debug again, when encounter the

     call delay_s
    

    in main function, there's an error in debug window, it's "error 65: access violation at I:0x81: no 'write' permission.; it means the address of next instruction was not pushed into stack and I think this causes the problem. When encounter

     RET
    

    , there's no value popped out of stack (and 0 value popped out instead), and the program restart at 0000h, not be returned to where it was called.

    Thanks and wait for your answers.

Children