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 Reply Children
  • 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.

  • there's an error in debug window
    is it the Keil simulator
    is it the SILabs emulator
    is it the ultramon monitor
    is it the acme whatschamacallit
    is it ....

    nobody can help you if tou keep secrets

    Erik

  • in main function, there's an error in debug window
    does it even compile without a prototype? or are you one of those that ignore warnings?

    Erik

  • does it even compile without a prototype?

    Ahem, Erik, are you aware that we're talking about a piece of assembly code here, as in: code to which the concept of a prototype declaration doesn't even apply? Nor that of "compiling", for that matter?

  • Ahem, Erik
    Sunday morning sleepies. OOPS

    still need to know what "the debugger" is

    Erik

  • Sorry for not supplying enough information.
    I'm just beginner using Keil C, and i don't know much. I don't mean to keep secret.
    I'm using Keil Simulator.

  • Erik;
    You need to cut some slack for OPS that use the Keil terms for their simulator. Keil calls it a "Debugger" in all their sales documents and in their operation manuals.
    Yes, it is a simulator but connected to a target board it can rightly be called a "Debugger".
    So, let the OPS call it a debugger. It's not difficult to discern what they mean.
    Bradford

  • It's not difficult to discern what they mean.
    ... where 'discerning' has led a thread astray

    Erik

  • Hello.
    I solved my problem.
    When initializing the stack, i used "MOV SP, #7F", so, I can't use "push" instruction because the address above 7F is SFRS, not for stack.
    Thanks

  • today, only a few derivatives will not 'run' the stack to 0xff you did not mention which derivative you were using.

    Most beginners makes omissions in their first visit to the forum, no 'blame', just remember.

    Erik