打印

向懂汇编的朋友请教个问题,关于数据类型的,谢谢!

[复制链接]
1896|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xyz_boy|  楼主 | 2011-3-29 22:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如下,是一个AD模块里的汇编函数,返回的是int型,请问怎么才能改成unsigned int型呢?汇编我看不懂,不知道光发这个函数大家能否看的懂?如需其他信息请告诉我,我再发上来,谢谢了顺便说下我遇到的现象吧,我用该模块采样比较小一点的电压时显示正常,但当电压超过一定值后得到的数据就会乱了,应该就是数据类型导致溢出,我在C里用IF X < 0, Y = (unsigned int) 2^15 - X但还是不行,不知道为什么,难道这个函数返回的已经错了吗?请赐教,谢谢!
;-----------------------------------------------------------------------------
;  FUNCTION NAME: void AdcScan(int iResult)
;
;  DESCRIPTION:
;    Returns an integer value from the ADC scanning system
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     Latest ADC result
;     A:X  => Integer value returned
;             A = MSB
;             X = LSB
;
;  RETURNS:   none
;
;  SIDE EFFECTS:
;    REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;-----------------------------------------------------------------------------
; A => MSB
; X => LSB
AdcScan:
_AdcScan:
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR >bADC_Index
   RAM_SETPAGE_IDX >aiADC_Results
   push  X  ; Push LSB
   push  A  ; Push MSB

   mov   A,[bADC_Index]              ; Get current index
   asl   A                           ; mult by to for correct index  (2 byte ints)
   mov   X,A                         ; Setup index register for result array.
   asr   A

   index FILTER_TABLE
   jz .no_filter                      ; jump if no filtering required

.filter:
   mov A,[X+aiADC_Results]        ; previous MSB
   push A                         ; store previous MSB
   mov [bTemp+HighByte],A         ; prestore MSB
   inc X                          ; point to LSB
   mov A,[X+aiADC_Results]        ; previous LSB
   mov [bTemp+LowByte],A          ; prestore LSB   

   asl [bTemp+LowByte]            ; mult LSB by 2
   rlc [bTemp+HighByte]           ; mult MSB by 2

   add [bTemp+LowByte],A          ; add to LSB
   pop A                          ; restore previous MSB
   adc [bTemp+HighByte],A         ; add to MSB

   pop A                          ; New MSB
   add [bTemp+HighByte],A         ; add new MSB
   pop A                          ; New LSB
   add [bTemp+LowByte],A          ; add new LSB
   adc [bTemp+HighByte],0x00      ; add carry flag

   asr [bTemp+HighByte]
  ; dividing sum
   rrc [bTemp+LowByte]            ; by 4 to obtain
   asr [bTemp+HighByte]           ; 3/4 + 1/4
   rrc [bTemp+LowByte]            ; filter

   mov A,[bTemp+LowByte]
   mov [X+aiADC_Results],A        ; write LSB to array
   dec X                          ; point to MSB
   mov A,[bTemp+HighByte]
   mov [X+aiADC_Results],A        ; write MSB to array

   jmp .next_scan

.no_filter:

   pop   A                           ; Pop MSB of result
   mov   [X+aiADC_Results],A         ; Write it to array
   inc   X                           ; Advance pointer to LSB
   pop   A                           ; Pop LSB of result
   mov   [X+aiADC_Results],A         ; Write it to array
.next_scan:
   mov   A,[bADC_Index]              ; Get current index
   index MVOLTSChannelPins           ; Get port/pin value of channel
   push A
   and A, F0h ; if port0
   jz .skip_InputClear
   pop A
   RAM_CHANGE_PAGE_MODE( FLAG_PGMODE_11b )
   lcall GlobalMux_InputClear
; Disconnect from the bus
   RAM_RESTORE_NATIVE_PAGING
; Restore native paging
   push A
.skip_InputClear:
   pop A
   inc   [bADC_Index]                ; Advance to next value
   cmp   [bADC_Index],(CMX_MVOLTS_IN_CHAN_COUNT) ; Check to see if we have if index should be reset.
   jc    .SetRefMux
   mov   [bADC_Index],0x00           ; Reset index back to zero

   // Set next reference setting
.SetRefMux:
   mov   X,>REF_TABLE                ; Get MSB of REF_TABLE        ( Swap Later )
   mov   A,<REF_TABLE                ; Put LSB of REF_TABLE in A   ( Swap later )
   add   A,[bADC_Index]              ; Add the ADC index value
   swap  A,X                         ; Move MSB to A, and LSB to X
   adc   A,0                         ; Add the carry from the add of the REF_TABLE LSB
                                     ; and ADC_Index.
   romx                              ; Get index value from reference table
   asl   A                           ; Shift mode 3 bits to left, to fit register alightment
   asl   A
   asl   A
   and   A,ARF_CR_REF                ; Mask off all non-valid bits
IF (SYSTEM_LARGE_MEMORY_MODEL)
   mov   reg[IDX_PP],SYSTEM_STACK_PAGE  ; Make sure index uses stack
ENDIF
   mov   X,SP
   push  A
   mov   A,reg[ARF_CR]
   and   A,~ARF_CR_REF               ; Mask out reference setting
   or    A,[X]                       ; Set new reference setting
   mov   reg[ARF_CR],A
   pop   A

SetGain:
   mov   A,[bADC_Index]             ; Get current channel ID
   index GAIN_TABLE          ; Get port/pin value of channel
   RAM_CHANGE_PAGE_MODE( FLAG_PGMODE_11b )
   lcall ADCBUF_SetGain
   RAM_RESTORE_NATIVE_PAGING
; Restore native paging

.SetMux:
   mov   A,[bADC_Index]              ; Get current index
   index  MVOLTSChannelPins ; Get port/pin value of channel
   push A ; save it
   and A, F0h ; if !port0
   jnz .not_port0
   pop A
   mov reg[AMUXCFG],00h ; switch column 1 comparator input to be the column mux
   RAM_CHANGE_PAGE_MODE( FLAG_PGMODE_11b )
   lcall AMUX8_InputSelect
   RAM_RESTORE_NATIVE_PAGING
; Restore native paging
   jmp .AdcScanEnd
.not_port0:
   pop A
   push A
   mov reg[AMUXCFG],80h ; switch column 1 comparator input to be the analog mux bus
   RAM_CHANGE_PAGE_MODE( FLAG_PGMODE_11b )
   lcall GlobalMux_InputSelect
   RAM_RESTORE_NATIVE_PAGING
; Restore native paging
   M8C_SetBank1
   pop A
   and A, 01h ; if pin is odd and not port0, then left mux bus, so unsplit the bus
   jz .split_mux
.unsplit_mux:
   and reg[DAC_CR], ~80h
.split_mux:
   M8C_SetBank0
.AdcScanEnd:   
   RAM_EPILOGUE RAM_USE_CLASS_4
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret

.SECTION

相关帖子

沙发
justrong| | 2011-3-30 15:57 | 只看该作者
您的是反汇编的吧!俺用汇编多少年了也看不懂!

使用特权

评论回复
板凳
aihe| | 2011-3-30 21:37 | 只看该作者
汇编不认得unsigned int的,要你自己弄的
怎么弄,看书去

使用特权

评论回复
地板
airwill| | 2011-4-1 08:56 | 只看该作者
汇编里的 IF 只是个宏而已, 是编译器计算的.
想搞明白还是看上去吧

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

14

主题

31

帖子

1

粉丝