Thread: 68HC11 assembly

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

    Join Date
    Sep 2004
    Posts
    31
    Rep Power
    10

    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
  2. #2
  3. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Alpharetta, GA
    Posts
    1,806
    Rep Power
    1570
    What sort of results, and how are they interesting?
    Last edited by Schol-R-LEA; November 10th, 2006 at 10:14 AM.
    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
  4. #3
  5. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Alpharetta, GA
    Posts
    1,806
    Rep Power
    1570
    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.
    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

IMN logo majestic logo threadwatch logo seochat tools logo