Help with assembly language debugging HCS12

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Help with assembly language debugging HCS12

2,211 次查看
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.

标签 (1)
0 项奖励
回复
5 回复数

1,868 次查看
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 项奖励
回复

1,868 次查看
jackrichey
Contributor I

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

0 项奖励
回复

1,868 次查看
kef2
Senior Contributor V

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 项奖励
回复

1,868 次查看
kef2
Senior Contributor V

(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 项奖励
回复

1,868 次查看
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 项奖励
回复