Help with assembly language debugging HCS12

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with assembly language debugging HCS12

975 Views
jackrichey
Contributor I

9590_9590.jpgcodesnip1.jpg

Was hoping someone could help me....I'm having trouble getting my multiplication loop working. I have to perform a check to see if the number is out of range (0-255) and if it is branch to either set_zero or set_ff. I'm storing the input variables in a reg x I have in memory. the two numbers are both positive, but blo flag keeps kicking in. the numbers are loading out of memory right. I think it has something to do with the fact that the result of the operation is a 16bit number, stored in the d reg. I tried adding an l in front of the blo, for long word, but that didn't help. all the other functions work as expected. If anyone has any idea, I'd really appreciate it.

Labels (1)
0 Kudos
5 Replies

632 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

what about:

;_______________________________________________________________________________

; variable/data section

;_______________________________________________________________________________

MY_EXTENDED_RAM: SECTION

xa         ds.b 1     ; input variable

xb         ds.b 1     ; input variable

xc         ds.b 1     ; result

ov_f       ds.b 1   ; overflow flag for multiplication; result is > 255

z_f        ds.b 1     ; zero flag for multiplication

;_______________________________________________________________________________

MyCode:     SECTION       ; code section

;_______________________________________________________________________________

main:                     ; routine is called after power on reset

Entry:

;_______________________________________________________________________________

      LDS   #$F00         ; set STACK; reset status: RAM is placed 800~FFF

      ;-------------------

      MOVB  #0,xa           ; innitialize variables to be multiplied

      MOVB  #0,xb           ;

MAINLOOP:

      LDAA xa                   ; prepare parameteres for sending to function

      LDAB xb

      XGDX                       ; X<=>D; as you wrote you store a,b in X

      JSR multiply

      INC  xa                     ; modify inputs

      INC  xb

      JMP MAINLOOP      ;

;_______________________________________________________________________________

multiply:

      CLR z_f                    ; clear flags

      CLR ov_f

      XGDX                        ; X<=>D

      MUL                          ; multiply

      STD  xc                     ; store result

                                         ; test result for given conditions and set flags        

      TBEQ D,zero           ; result is zero -> go to "zero" for processing

      TBNE A,overflow     ; result>255     -> go to "overflow" for processing

      RTS                           ; return

zero:

      MOVB #1,z_f         ; set ctm's zero flag

      RTS

overflow:

      MOVB #1,ov_f        ; set ctm's overflow flag

      RTS

;_______________________________________________________________________________

Best regards,

Ladislav

0 Kudos

632 Views
jackrichey
Contributor I

and the operation is not triggering the c flag, the number is well withing range of 64k.

0 Kudos

632 Views
kef2
Senior Contributor IV

1. MUL does unsigned multiply

2.C flag has nothing to do with the "sign" of result.

3. Sign of 16bit result is bit15 of result, not bit7, which MUL copies to C.

0 Kudos

632 Views
kef2
Senior Contributor IV

(What the beep you are using picture to show text? )

1. there's no BLO flag, please use correct terminology

2. You should download CPU12 reference manual. 6.7 Glossary explains each instruction in detail. MUL instruction changes only C flag. MUL makes bit 7 of result reg D(B) copied to C flag.

0 Kudos

632 Views
jackrichey
Contributor I

uh yeah, I have the reference manual. and to be precise, when I multiply the positive number in accumulator a with the positive number in accumulator b, the positive result is stored in register d. I cannot figure out why the positive number in register d is branching lower. branch lower checks the n flag in the ccr. if you couldn't tell, I'm new to assembly language programming.

0 Kudos