MC68HC11 homework question?

Discussion in 'Homework Help' started by joepauljig, Sep 11, 2008.

  1. joepauljig

    Thread Starter New Member

    Sep 11, 2008
    3
    0
    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=4J...&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.
     
  2. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    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
     
  3. joepauljig

    Thread Starter New Member

    Sep 11, 2008
    3
    0
    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?

    Code ( (Unknown Language)):
    1.            ORG     $00
    2. array      FCB     20
    3.            ORG     $2000
    4.            LDY     #array
    5.            CLRA
    6.            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.
     
  4. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    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:
    Code ( (Unknown Language)):
    1.  
    2. 1:            ORG     $00
    3. 2: array      FCB     20
    4. 3:            ORG     $2000
    5. 4:            LDY     #array
    6. 5:            CLRA
    7. 6:            LDAB    0,Y
    8.  
    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
     
  5. joepauljig

    Thread Starter New Member

    Sep 11, 2008
    3
    0
    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.

    Code ( (Unknown Language)):
    1.  1: ANSWER    ORG    $3020    ;Start address of answer
    2.  2:           RMB    20       ;Reserves memory locations for answer
    3.  3:           ORG    $2000    ;Start address of program
    4.  4:           LDY    $3000    ;Set y to point at the array
    5.  5: AGAIN     CLRA            ;Initiaize A to 0
    6.  6:           LDAB    0,y     ;Load array into accumulator B
    7.  7:           LDX    #4       ;Load X with the divider # 4
    8.  8:           IDIV            ;Divide array by 4
    9.  9:           STX    ANSWER   ;Store the answer in memory
    10. 10:           INY             ;Point Y to next number in array
    11. 11:           INC    ANSWER   ;Go to next memory location for answer
    12. 12:           CPX    #62      ;Check to see if we are finished with array
    13. 13:           BNE    AGAIN    ;If not, move on to next array #
    14. 14: EXIT      SWI
    15. 15:           END
     
  6. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    "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! :)


    Code ( (Unknown Language)):
    1.  
    2. ---------
    3.  1: ANSWER    ORG    $3020    ;Start address of answer
    4.  2:           RMB    20       ;Reserves memory locations for answer
    5.  3:           ORG    $2000    ;Start address of program
    6.  4:           LDY    $3000    ;Set y to point at the array
    7.  5: AGAIN     CLRA            ;Initiaize A to 0
    8.  6:           LDAB    0,y     ;Load array into accumulator B
    9.  7:           LDX    #4       ;Load X with the divider # 4
    10.  8:           IDIV            ;Divide array by 4
    11.  9:           STX    ANSWER   ;Store the answer in memory
    12. 10:           INY             ;Point Y to next number in array
    13. 11:           INC    ANSWER   ;Go to next memory location for answer
    14. 12:           CPX    #62      ;Check to see if we are finished with array
    15. 13:           BNE    AGAIN    ;If not, move on to next array #
    16. 14: EXIT      SWI
    17. 15:           END
    18.  
    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! :D

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


    --Rich
     
Loading...