News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

(HCS12 Microcontroller) Which branch is appropriate for this loop?

Started by koroshin, March 17, 2016, 04:25:20 PM

Previous topic - Next topic

koroshin

What I'm really stuck on is how I'm supposed to make this loop properly I tried doing every combination for each branch but it either never stops or it stops at the wrong number of loops (supposed to stop after amount of values in RPN_START). I even tried what I did in a previous lab which also failed to work so I'm completely lost as to how I'm supposed to get this program to loop. I understand that the RPN_OUT is the end pointer of the array so I tried putting RPN_START with CPY to compare the values but doing that made it stop after one loop. So I don't know at all which branch I'm supposed to use. Any help/tips/advice would be greatly appreciated. I tried that but RPN_END points to RPN_OUT so it gives the same results as RPN_END does. I tried #RPN_OUT-1 and that looped correctly but gave a couple of warning and didn't store the correct answer. I tested the in between code before and it worked how it was supposed to. So I'm completely lost now ;-; 
Thank you so much!

ORG     DATA
;RPN_IN    FCB     $06,$03,$2F,$04,$2A,$02,$2B  ; 63/4*2+=10
;RPN_IN    FCB     $05,$01,$02,$2B,$04,$2A,$2B,$03,$2D  ; 512+4*+3-
;RPN_IN    FCB     $02,$03,$2A,$05,$2A,$02,$2F,$01, $2B ; ( ( (2 * 3) * 5) / 2) + 1
RPN_IN    FCB     $11,$10,$2F,$15,$2A   ; ( (11 / 10) ) * 15
RPN_OUT   RMB     1

RPN_START FDB     RPN_IN                ; Pointer to start of RPN array
RPN_END   FDB     RPN_OUT-1             ; Pointer to end of RPN array         
ANSWER    RMB     1
TEMP      FCB     $00       
      ORG     PROG

Entry:                          ; KEEP THIS LABEL!!

      LDS      #PROG
      LDX      #RPN_START  ;should I put a # in front of the array??
      LDY      #RPN_END    ;should I put a # in front of the array??
      LDAB     ANSWER

LOOP:
LDAA  B,X
...
RET:
INCB
CMPB  RPN_END ;should it be RPN_END-1 or just RPN_END?
BNE   LOOP      ;unsure which branch, I tried BHI, BLO, BEQ, BLT, and BLE (none of them work)
PULA
STAA ANSWER

      ; Branch to end of program
      BSR     FINISH


wjr

I am not familiar with the HCS12, but it seems like you are setting up X as an index register, so perhaps instead of INCB CMPB you should have INX CMPX (and then use BLE if using RPN_END equal to RPN_OUT-1).