Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 4th, 2006, 05:51 AM
gtoughuk gtoughuk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 1 gtoughuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 41 sec
Reputation 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

}

Reply With Quote
  #2  
Old May 4th, 2006, 04:48 PM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,418 Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 47 m 27 sec
Reputation Power: 334
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.

Reply With Quote
  #3  
Old May 4th, 2006, 05:11 PM
Schol-R-LEA's Avatar
Schol-R-LEA Schol-R-LEA is offline
Commie Mutant Traitor
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Location: The People's Republic of Berkeley
Posts: 1,082 Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 10 h 16 m 50 sec
Reputation Power: 446
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).
__________________
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 ShortUnderstanding the C/C++ Preprocessor
Taming PythonA 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

Last edited by Schol-R-LEA : May 6th, 2006 at 06:20 PM.

Reply With Quote
  #4  
Old March 1st, 2008, 08:13 PM
Rufusw Rufusw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 4 Rufusw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 38 sec
Reputation 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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Asm help needed


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway