1

I just fell in love with this particular microcontroller, 68hc11 has an amazing architecture.

I'm not an expert but i want to improve, assembly is kinda hard but i want to program this microcontroller.

This assembly code will execute from $100, will allocate a 200-byte array at $800, and will initialize that array with the values 200, 199, … 1. (descending order).

Vreset              equ       $FFFE
RAM                 equ       $800
ROM                 equ       $100

ARRAY_SIZE          equ       200

                    org       RAM

array               rmb       ARRAY_SIZE

                    org       ROM

Start               ldx       #array
                    ldaa      #ARRAY_SIZE
Loop                staa      ,x
                    inx
                    deca
                    bne       Loop

                    bra       *

                    org       Vreset
                    dw        Start

I want to get the two highest values from a given array.. i mean, i want to create an array, give 10 values (stored inside an array) and finally obtain the two highest values:

Example:

the array may contain these values:

5 7 9 96 57 58 1 5 6 9

I would like to obtain this output:

96 58

Can help me to do this? I'm kinda lost :/

JustToKnow
  • 785
  • 6
  • 23
  • Can you do it in C? It is unclear if you need an algorithm or already have one, or otherwise, if you need help with some specific assembly instruction, or translating a for-loop or if-statement to assembly. – Erik Eidt Jun 06 '20 at 21:48
  • 1
    Hey Erik, thank you for replying!. What do you mean?. I'm not really into 'C' at all – JustToKnow Jun 06 '20 at 21:50
  • 1
    Ok, can you solve this in any programming language at all, including pseudo code? In other words, do you have an algorithm? – Erik Eidt Jun 06 '20 at 21:50
  • 3
    Oh, yeah.I can do it in Java or C# but i want to program it in assembly code, using the 68hc11 instructions. Do you get me? – JustToKnow Jun 06 '20 at 21:53
  • 2
    Sure, so take your Java solution and translate it into assembly, line by line. If you get stuck, ask as specific question about the construct you're having trouble translating. – Erik Eidt Jun 06 '20 at 21:54

1 Answers1

2

The 68HC11 is a classic MCU architecture that was (and possibly still is, to some extent) taught in many universities.

Officially, it is end-of-life. But, due to momentum, many people are still actively using it either by IP equivalents loaded in FPGAs, or clones from companies such as Tekmos.

To create the array, use code similar to what you showed. My example uses constant array in ROM.

As to your question finding the two highest values, there are many possible solutions. Here's just one to get you started:

Vreset              equ       $FFFE
ROM                 equ       $100

                    org       ROM

array               fcb       5,7,9,96,57,58,1,5,6,9
;ARRAY_SIZE         equ       *-array

Start               ldx       #array              ;X -> array
                    ldaa      ,x                  ;let A keep the 1st maximum (assume 1st element)
                    clrb                          ;let B keep the 2nd maximum (assume zero)
Loop                inx                           ;X -> next array element
                    cpx       #array+::array      ;(ASM11 idiom, ::array = 10 i.e., number of elements)
;                   cpx       #array+ARRAY_SIZE   ;(alternative for most assemblers)
                    bhs       Done                ;if past the array end, done

                    cmpa      ,x                  ;compare with current array element
                    bhi       DoB                 ;if already 1st maximum, skip
                    tab                           ;update 2nd maximum with previous 1st
                    ldaa      ,x                  ;else A = new maximum
                    bra       Cont
;                   bra       Loop                ;(optimization of previous line)

DoB                 cmpb      ,x
                    bhi       Cont                ;if already 2nd maximum, skip
;                   bhi       Loop                ;(optimization of previous line)
                    ldab      ,x                  ;else B = new maximum <= A

Cont                bra       Loop                ;repeat for all array elements

Done                bra       *                   ;A = 1st maximum, B = 2nd maximum <= A

                    org       Vreset
                    dw        Start
tonypdmtr
  • 3,037
  • 2
  • 17
  • 29
  • 1
    Actually, it's not end-of-life, but strongly not recommended for new designs. – tonypdmtr Jun 07 '20 at 20:42
  • 2
    When you find a new max element, you need to save the old max element as the 2nd max rather than just dropping it -- in practical terms, you need a `tab` just after `bhi DoB` – Chris Dodd Jun 07 '20 at 20:50
  • 1
    Good catch. Thanks. And there was another error. Initializing B to the first value is wrong as it could be the highest value. So, assuming unsigned values, I initialized to zero. – tonypdmtr Jun 07 '20 at 21:36
  • 1
    Thank you very very much for replying,Tony.. I'm checking it out. PS: i'm studying assembly language by my own and a friend of mine told me this MC was great! – JustToKnow Jun 07 '20 at 21:57
  • @tonypdmtr, just a question: why did you use the ROM instead of the RAM? – JustToKnow Jun 07 '20 at 22:01
  • 1
    @Student_new It's an example, and I wanted to avoid writing the code for array initialization. You would normally work from RAM though. The main code does not change. – tonypdmtr Jun 07 '20 at 22:08
  • @tonypdmtr Tony, can take a look at this (kinda interesting :) ): https://stackoverflow.com/questions/62296789/swapping-positions-hc11 – JustToKnow Jun 10 '20 at 06:02
  • Hey @tonypdmtr , can check this thread? https://stackoverflow.com/questions/62624307/simple-loop-reading-temperature-mc68hc?noredirect=1#comment110748230_62624307 – JustToKnow Jun 28 '20 at 17:27