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:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old November 6th, 2006, 03:59 PM
drogonevets drogonevets is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 31 drogonevets User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 28 m 36 sec
Reputation Power: 4
68HC11 assembly

hello,
I have been given an assignment of a "simple" bubble sort in 68HC11 assembly code
can anyone help me, this is what i have so far (and getting interesting results

Code:
	ORG	$0000

ArraySize  	EQU  	9		all arrays will be this big
swapVar		EQU	$0b

array1		RMB	ArraySize*1	array of bytes

counter		RMB	1		used as a loop counter
pointer		RMB	2		used as a pointer to an array element

	ORG	$E000
BEGIN
	CLRB	
	LDX	#array1
Loop1	CMPB	#ArraySize
	BGE	EndLoop1
	ABX			
	STAB	0,X		
	INCB
	BRA	Loop1

EndLoop1

	CLRB
	LDX	#array1
	LDAB	#ArraySize	
	LDY	#array1

sort	
	LDAA	0,Y
	CMPA	1,Y
	BLS	endSwap
swap
	PSHA
	TBA
	PULA
 	INY
	BRA 	sort
endSwap		
	INY
	DECB
	CMPB	#00
	BHI	sort	
endSort
	
end 	BRA 	end


any ideas

D

Reply With Quote
  #2  
Old November 10th, 2006, 02:25 AM
Schol-R-LEA's Avatar
Schol-R-LEA Schol-R-LEA is online now
Commie Mutant Traitor
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Location: The People's Republic of Berkeley
Posts: 1,083 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 47 m 7 sec
Reputation Power: 446
What sort of results, and how are they interesting?
__________________
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 : November 10th, 2006 at 10:14 AM.

Reply With Quote
  #3  
Old November 11th, 2006, 11:32 AM
Schol-R-LEA's Avatar
Schol-R-LEA Schol-R-LEA is online now
Commie Mutant Traitor
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Location: The People's Republic of Berkeley
Posts: 1,083 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 47 m 7 sec
Reputation Power: 446
OK, I've looked at the code a bit, and I see at least one thing, even without knowing the particular processor - I can work out what many of the mnemonics mean, but not all of them. I did find a chart of the opcodes on a quick Google search, which I'm using for reference, and so far most of them have meant what I expected them to mean. Another search found some general information about the assembly language syntax, too. However, I'm not going to pretend to really know 68HC11 assembly, so I will probably misunderstand some things.

In the first loop, which apparently is meant to initialize the array, the intended initialization seem to be [0, 8] in ascending order. However, the array index increment 'ABX' is cumulative; you are adding the current value of B to the previous pointer, which will jump exponentially (addr + 0, then addr + 0 + 1, then addr + 0 + 1 + 2, then addr + 0 + 1 + 2 + 3, and so on). If the array size is nine, then the pointer will pass the end of the array in five iterations.

One way to fix this is to separate the memory index increment from the initializer increment; since they really are different operations, and can be done with one-cycle instructions, you don't lose anything by doing so.

Code:
	LDX	#array1		* first addr in the array
        LDAA    #ArraySize      * the size of the array
        CLRB			* clear the array initializer
        BRA     Init_test       * jump to the first test

Init_loop
	STAB	0,X		* init the currently indexed value
	INX                     * increment the array index
	INCB                    * increment the initializing value
Init_test
        CBA			* Is B < ArraySize?
        BLT Init_loop

(Not tested code, just used as an example.)

You'll notice two things about this version. First, I used the A accumulator to hold the value of ArraySize, to avoid an extra memory reference; while it can be tricky on a very constrainted register set like this one, it is preferably to use registers for as many operations as possible, especially in loops, as memory references are time-consuming. Also, I changed the order of the branches around, so that it skips a test at the bottom instead of testing at the top and then doing an uncoditional branch from there. Done this way, you can avoid one branch per iteration, which generally speaking is a good thing. Also, it allows you to use a 'while' type condition rather than an 'until' type condition, which most programmers find more familiar.

Actually, given that you are using the same array each time in this version, it may make more sense just to hard-code the starting array values as rather than initializing them; this way you can also test it with data that isn't already ordered; for example,

array1 FCB 5, 2, 23, 42, 17, 69, 57, 13, 255

AFAICT, the value set using FCB doesn't actually need to remain constant during the program run; from what I gather, 'Form Constant Byte' just means that it is initialized to a constant value. If I am mistaken in this, you could still use this sort of pre-initialized array as a source value, which in some ways would actually make the sorting easier (since you can sort to the second array without having to do changes in-place).

Alternately, and probably most desireably, you could get the values fro the user somehow. However, I don't know offhand much about the I/O capabilities of the SBC or simulator you are testing this on, so I can't give any examples.

Last edited by Schol-R-LEA : November 11th, 2006 at 12:20 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > 68HC11 assembly


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