Controlling time intervals in Assembly

Discussion in 'Computer Software and Operating Systems' started by Lucifer666, Nov 23, 2016.

  1. Lucifer666
    OP

    Lucifer666 all the world needs is me

    Member
    1,490
    702
    Apr 22, 2011
    The Fourth Dimension
    I have assembly code laid out in the following structure (I'll use pseudo commands for readability). Its function is to remain in a state for 0.5s then another state for 0.5s, repeatedly.

    Code:
    main:           //do things
                    //do things
                    //do things
    
                    call ofs //ofs is a 0.5s time delay command
                    //do things
                    //do things
                    //do things
    
                    call ofs //ofs is a 0.5s time delay command
    rjmp main
    
    ofs:          //program time delay
                  ret
    I've re-written it, trying to preserve its functionality, but the result is a 0.5s delay after the first set of 'things' to do and then a 1.5s delay after the second set of things. Why does this happen? Code below:

    Code:
    main:           //do things
                    //do things
                    //do things
    
                    call ofs //ofs is a 0.5s time delay command
                    //do things
                    //do things
                    //do things
    
    
    ofs:          //program time delay
                  ret
    rjmp main
     
    Last edited by Lucifer666, Nov 23, 2016