Calculating an Average in HCS08 Assembly

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Calculating an Average in HCS08 Assembly

ソリューションへジャンプ
2,310件の閲覧回数
rsheldon
Contributor II

Hello,

 

I am wondering the simplest and best way is to calculate an average of 3 8-bit numbers using HCS08 Assembly code.  I'm getting stuck on what happens when adding the first two numbers results in an overflow and how to proceed on getting the final sum before dividing by 3 (which I was planning on doing using the DIV instruction, but that depends on your suggestions).

 

Thanks,

 

RTS

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,068件の閲覧回数
peg
Senior Contributor IV

Hello rsheldon,

 

Here is one way to find the average of 3 8-bit numbers:

 

 

  CLRA  PSHA   ;zero a place on the stack for high byte of addition result  LDA value1  ADD value2         ;add first two values  BCC XXX1  INC 1,SP  ;store possible rolloverXXX1  ADD value3   ;add third value  BCC XXX2  INC 1,SP  ;add possible rollover to high byteXXX2  PULH   ;low byte of result already in A, put high byte in H  LDX #3  ;set divisor  DIV   ;do the division     ;the result is in A with any remainder in H

 

 

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,069件の閲覧回数
peg
Senior Contributor IV

Hello rsheldon,

 

Here is one way to find the average of 3 8-bit numbers:

 

 

  CLRA  PSHA   ;zero a place on the stack for high byte of addition result  LDA value1  ADD value2         ;add first two values  BCC XXX1  INC 1,SP  ;store possible rolloverXXX1  ADD value3   ;add third value  BCC XXX2  INC 1,SP  ;add possible rollover to high byteXXX2  PULH   ;low byte of result already in A, put high byte in H  LDX #3  ;set divisor  DIV   ;do the division     ;the result is in A with any remainder in H

 

 

0 件の賞賛
返信
1,068件の閲覧回数
rsheldon
Contributor II

Thanks! This works perfectly

0 件の賞賛
返信