Thread: Asm help needed

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    1
    Rep Power
    0

    Asm help needed


    For some college work we have to use a BL2000 wildcat board with a Rabbit2000 microprocessor to turn on LED DS6 for 5 seconds then off for 5 seconds then repeat. I have managed to get it to turn on and off when debugging but the delay loop isn't repeating. Any help would be most greatful

    We have to use dynamic c.

    main()

    {
    printf("Assembly Language Program Development Assignment: Objective 2");

    #asm
    REP2: LD A, 84h
    IOI LD (SPCR),A
    IOI LD A,(PBDR)
    IOI LD (PADR),A

    REP: LD BC, 850
    DEC BC
    JP NZ, REP

    LD A, 0xff
    IOI LD (SPCR),A
    IOI LD A,(PBDR)
    IOI LD (PADR),A

    REP1: LD BC, 850
    DEC BC
    JP NZ, REP1
    JP REP2
    #endasm

    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    It sounds like your problem is mainly in the flow control logic, which means people could help you even if they aren't very familiar with that assembly language. However, for those people to help you, they would need some indication of what the code actually means (comments, for example). I'm just saying this because there probably aren't a whole lot of people here who know that language, but there are potentially many people who could help you if your bug is indeed in the flow control.
  4. #3
  5. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Alpharetta, GA
    Posts
    1,806
    Rep Power
    1570
    While I don't know much about the microprocessor and SBC in question (though I have learned that the Rabbit series are extensions of the familiar Z80 and Z180 family), I was able to look up the Wildcat SBC documentation, the processor op-code reference, and for using inline assembly in Dynamic C. After checking a few things, I can make a few suggestions right off.

    First off, you are using a fixed delay loop to time the LED toggling. Now, I usually would recommend against busy-waiting, as fixed timing loops can be rather brittle. However, since this is embedded code, it is not so problematic. What is problematic is way the loop index is updated; if you look carefully at the code in this section, you should find the bug you are looking for.

    As a side point, you use two separate, identical code sections to handle the two sets of timeouts, which, aside from taking up extra space on a rather memory-constrainted system, is simply bad design; this is particularly important in this case since it seems likely that the timing loops are the source of the problem you are having. I'm guessing that you professor hasn't covered subroutine calls yet, but fortunately, they are fairly easy to do on this processor using the CALL and RET instructions.

    I also noticed that the code for setting and testing the LED status was also duplicated, and could easily be broken out into a subroutine as well; doing this not only saves memory, but makes debugging easier, since it isolates the different parts of the program and allows you to study them independently. Indeed, I probably would not have noticed the loop index problem mentioned above if I hadn't tried re-writing the code this way (see below). [EDIT: I was going to answer the problem outright, but I figured it would be better to give a hint and let you figure it out. The changes I've made to the code below should make it clearwhere the problem lies; fortunately, you only need to make two trivial changes to fix it.]

    In fact, you probably should remove the assembly code from the main() function and put it in it's own function outright. Finally, you should be able to replace the JP (jump absolute) instructions with JR (jump relative) without any trouble, though it's not a big deal either way; similarly, the 'decrement word register and jump if not zero' can be done as a single DWJNZ instruction, though you may need to adjust the timing of the loop to account for the difference in clock cycles it uses.

    Below is a modified version of your code following this recommendation (I've also changed the labels to improve readability, and added some debugging printouts):

    Code:
    main()
    
    {
        printf("Assembly Language Program Development Assignment: Objective 2");
        
        toggle_led();
    
        /* include a sanity check in case the assembly routine ever exits */
        printf("Sanity Check failed: The function toggle_led() ended.");
    
    }
    
    debug toggle_led()
    {
       #asm
    ;; the main loop of the code is intended to toggle the
    ;; LED at location SPCR (or at least this is what I gather)
    TOGGLE::
             ; set the LED, then wait five seconds
             LD A, 84h
             CALL SET_LED
             CALL TIME_OUT
    
             ; clear LED, then wait another five seconds
             LD A, 0xff
             CALL SET_LED
             CALL TIME_OUT
    
             JR TOGGLE ; repeat the whole process
    
             ; debugging printout, in case the code gets past the loop
             ; the 'C' directive tells it to switch back to C for 
             ; one line of code     
             C printf("Sanity Check Failed: Code got past the end of the toggle loop.");
    
             RET  ; backstop the function, in case 
                    ;it gets past the loop somehow
            
    ;; Subroutines
    
    ; load value of register A to LED setting register and
    ; return the value from the LED status
    SET_LED::
             IOI LD (SPCR),A
             IOI LD A,(PBDR)
             IOI LD (PADR),A
             RET
    
    ; count out a timing loop
    TIME_OUT::
             LD BC, 850
    
             DWJNZ TIME_OUT ; decrement and test BC
             RET
    
    	#endasm
    
        printf("Sanity Check failed: the assembly code has unexpectedly completed.");
    
    }
    Since I don't have access to the compiler and SBC in question, I have no way of knowing if this code is correct, but it should give you a starting point. I would recommend checking out the BIOS to see if there's a better alternative to the timing loop (you might want to look at the periodic interrupt and the timer in particular).
    Last edited by Schol-R-LEA; May 6th, 2006 at 06:20 PM.
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    4
    Rep Power
    0
    DEC BD 850???

    The rabbit 2000 processor runs at 22100000Hz, thats clocks per second (22.1Mhz), theres probably about 10, maybe 20 clocks in that cycle... 20 x 850 = 17000

    Thats about 0.0007 seconds

IMN logo majestic logo threadwatch logo seochat tools logo