MC68HC11 homework question?

joepauljig

Joined Sep 11, 2008
3
Hello,

I am stuck on a lab assignment problem from the book MC68HC11: An Introduction Software and Hardware Interfacing. Here's a link to the specific problem. It's problem L2.7; http://books.google.com/books?id=4JqlQJd2kvYC&pg=PA111&lpg=PA111&dq=write+a+program+to+divide+each+element+in+an+array+by+4&source=web&ots=GnqlIbvy7Q&sig=JBGsrBaQIho8Qoze3jcyhJ925gQ&hl=en&sa=X&oi=book_result&resnum=2&ct=result

The problem states; Write a program to divide each element of an array by 4. The array has 20 8 bit elements and is stored at $00-$13 for EVBU (the one we are using). To test the program define an array using the directive FCB.

I am thoroughly confused on how to write this program. The book has little information in chapter 2 about arrays and division and I'm not for sure how to even get started on this program. I would greatly appreciate any assistance or guidance on this problem.

Thanks again.

RiJoRI

Joined Aug 15, 2007
536
First, an array is just a series of things. They can be bytes, words, etc. I kind of picture them as plastic bins set up next to each other:
[][][][][][][]

First, just set up a variable and stick a number into it, Then figure out how to divide it by four, and save the result to either the original variable, or a new one. THen, you will need to go set up an array, and fill the array with numbers. Apply your division routine to each entry in the array.

HInt: use an index register like X or Y.

--Rich

joepauljig

Joined Sep 11, 2008
3
Thanks so much for your suggestions. I have started writing the program and am having a little trouble pulling it all together. I think I have the array variable setup correctly and am going to use index register y for the array Can you look at the code I have so far and tell me if I'm on the right track?

Rich (BB code):
           ORG     $00 array FCB 20 ORG$2000
LDY     #array
CLRA
LDAB    0,Y
I hate to keep bothering you but I'd really like to completely understand what I am doing. I'm a little lost at this point in the code on where to go next to start the division process and then store the answer in the right place.

Thanks again.

RiJoRI

Joined Aug 15, 2007
536
I'll help, as far as I can. My nearest experience to the 6811 has been the 6809.
I've added line numbers for ease of reference:
Rich (BB code):
1:            ORG     $00 2: array FCB 20 3: ORG$2000
4:            LDY     #array
5:            CLRA
6:            LDAB    0,Y
Line 1 says that you're starting at address 0000. I'm assuming the RAM starts at that address.

The FCB command "...may have one or more operands separated by commas.
The value of each operand is truncated to eight bits, and is stored in
a single byte of the object program. Multiple operands are stored in
successive bytes. The operand may be a numeric constant, a character
constant, a symbol, or an expression. If multiple operands are
present, one or more of them can be null (two adjacent commas), in
which case a single byte of zero will be assigned for that operand.
An error will occur if the upper eight bits of the evaluated operands'
values are not all ones or all zeros."

So it is used for Constant data.

Look into the FILLcommand: "FILL MEMORY

(<label>) FILL <expression>,<expression>

The FILL directive causes the assembler to initialize an area of
memory with a constant value. The first expression signifies the one
byte value to be placed in the memory and the second expression
indicates the total number of successive bytes to be initialized. The
first expression must evaluate to the range 0-255. Expressions cannot
contain forward references or undefined symbols."

These directives are from the "MOTOROLA FREEWARE 8-BIT CROSS ASSEMBLERS USER'S MANUAL." You assembler may have different directives.

Line 3 says that you're starting at address $2000. I'm assuming the ROM starts at that address. Line 4 loads Y with the address of array. This is good. Line 5 clears the accumulator A. This is not bad, assuming you are going to do something with A. You may wish to delay clearing it until you need to. Line 6 is loading Accumulator B from what Y is pointing to. Now you need to divide this by four. Again, I'll assume your teacher is not interested in floating of fixed point arithmetic, and I shall leave you to discover how division is done with this chip. I think there is an IDIV command, but there is another way that's pretty quick. --Rich Thread Starter joepauljig Joined Sep 11, 2008 3 Thanks so much RiJoRI for your help. You don't know how much your last explanation has helped me. I did go ahead and finish writing the program and I used the build function in Axiom and the program compiled without any errors. The problem I have now is that it will not load and execute. I was wondering if you would mind looking over my program to see if anything looks odd to you. I know you said earlier that you didn't have much experience with the micro-controller we're using but your knowledge far exceeds mine. I don't want you to think I'm trying to get you to do my assignment for me. I would just appreciate any suggestions that you may have for me. I reread the problem and changed the program around a little. I'm not using FCB anymore because that was just supposed to be to test the program with. The actual array is supposed to be stored at$3000-$3013 and thats what I have attempted to do. The program starts at$2000 and the answers are supposed to be stored starting at $3020. I added lines numbers to help with explanations if necessary. Once again, I appreciate your assistance. I have a better understanding now and would love to fully understand this program. Rich (BB code):  1: ANSWER ORG$3020    ;Start address of answer
2:           RMB    20       ;Reserves memory locations for answer
3:           ORG    $2000 ;Start address of program 4: LDY$3000    ;Set y to point at the array
5: AGAIN     CLRA            ;Initiaize A to 0
6:           LDAB    0,y     ;Load array into accumulator B
7:           LDX    #4       ;Load X with the divider # 4
8:           IDIV            ;Divide array by 4
10:           INY             ;Point Y to next number in array
12:           CPX    #62      ;Check to see if we are finished with array
13:           BNE    AGAIN    ;If not, move on to next array #
14: EXIT      SWI
15:           END

RiJoRI

Joined Aug 15, 2007
536
"I don't want you to think I'm trying to get you to do my assignment for me."

I don't, and even if I did, my comments were hardly anywhere near doing your assignment for you!

Rich (BB code):
---------
1: ANSWER    ORG    $3020 ;Start address of answer 2: RMB 20 ;Reserves memory locations for answer 3: ORG$2000    ;Start address of program
4:           LDY    \$3000    ;Set y to point at the array
5: AGAIN     CLRA            ;Initiaize A to 0
6:           LDAB    0,y     ;Load array into accumulator B
7:           LDX    #4       ;Load X with the divider # 4
8:           IDIV            ;Divide array by 4
10:           INY             ;Point Y to next number in array
12:           CPX    #62      ;Check to see if we are finished with array
13:           BNE    AGAIN    ;If not, move on to next array #
14: EXIT      SWI
15:           END
Line 5: I still do not understand why Acc. A is being cleared.
Lines 9 & 11: Grab the HC11 manual, and see what these two commands are doing.
Line 12: Where is X incremented?

If you do not have one, may I suggest you get a simulator for the 68HC11? There are some free ones available on the 'net, and they are good for testing small programs such as yours. Single-stepping through a problematic piece of code is a great way to find certain problems. You will be able to see what the micro will do; that is, how it interprets what you told it to do. Remember -- micros are STUPID -- they do what you tell them to do, not what you want them to do!

And, finally, look at the ASL/ASR, LSL/LSR, ROL/ROR instructions.

--Rich