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 March 2nd, 2008, 11:12 AM
brad sue brad sue is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 46 brad sue User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 13 m 34 sec
Reputation Power: 3
Use of registers

Hi,
I have a problem this question.
count the number of values in array data1 that equal the corresponding value in the array data2. both arrays have length 100.

Code:
; initialization of pointers
   ldx   data1
   ldy   data2
   ldab  count  ;initialize counter
loop:
      ldaa  1,x+   ;going through data1      
      ldab   1,y+   ; going through data2
      CBA           ; compare A-B
      bne    loop  ; if not 0 branch back  to loop
      inb            ; increment B
      cmpb #100   ; check if end of array
      bne    loop
      swi  ; end of program


My problem here is that I have I am sure I dont use the accumulator B well .
I used it for initialization and to get the data through data2.
Can please someone suggest me how to handle this problem?

Thank you
B

Last edited by brad sue : March 2nd, 2008 at 11:22 AM.

Reply With Quote
  #2  
Old March 2nd, 2008, 12:59 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
Yes, you've definitely got a problem using B like that; the counter is getting overwritten when you get the value from data2, and isn't saved or restored anywhere. Your options are to either push the counter onto the stack while performing the compare, then restoring it for the loop indexing, or else use a memory compare rather than loading the value at the data2 into B. The latter is probably the better alternative.
Code:
loop:
      ldaa  1,x+   ;going through data1      
      cmpa 1,y+  ; compare A directly to data2 
      bne    loop  ; if not 0 branch back  to loop
      incb            ; increment B
      cmpb #100   ; check if end of array
      bne    loop


I'm not certain if this is right, as I don't know the processor that well, but from what I see in the instruction set, it should work.

For the pointers, are you sure you want ldx/ldy and not leax/leay? If I am not mistaken, as it is written now, what you are loading into X and Y are the values held in the locations data1 and data1. If those are pointers, then that is correct; but if those are the actual arrays, as seems to be the case, then you want to load their effective addresses instead. Since you don't show the two strings, I'm not sure which is the case.
__________________
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 : March 2nd, 2008 at 01:01 PM.

Reply With Quote
  #3  
Old March 2nd, 2008, 01:34 PM
brad sue brad sue is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 46 brad sue User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 13 m 34 sec
Reputation Power: 3
Thank you Schol-R-LEA,

I believe it should work too. I was not aware that I can use the indexed addressing with cmpa instruction.

You are right for
Code:
ldx   data1
ldy   data2


It should be:
Code:
ldx   #data1
ldy   #data2

This is how we usually initialize pointers in the course.

Thank you again
B

Reply With Quote
  #4  
Old March 2nd, 2008, 01:45 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
Quote:
Originally Posted by brad sue
I was not aware that I can use the indexed addressing with cmpa instruction.

To be fair, that's the part I wasn't certain about, though if I am reading the documentation correctly, you can; like most CPUs with a tightly limited register file, the 6800 series (which the 68HCS12 is a descendant of - not, as someone recently claimed, the 68000, which is a completely different design) has a lot of memory-direct operations. Otherwise, you'd need to push B, load the test values and do the comparison, thern pop B for the loop. Neadless to say, you really would rather avoid that.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Use of registers


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 4 hosted by Hostway