📄 clz.asm
字号:
; File : clz.asm
; By : Eric Shufro
; For : ARM926EJ-S
; Note : This routine will also work on any other ARM CPU
; with instruction set version >= 5
;********************************************************************************************************
; CODE GENERATION DIRECTIVES
;********************************************************************************************************
RSEG CODE:CODE:NOROOT(2)
CODE32
;********************************************************************************************************
; PROTOTYPES (C equivalent in ASM)
;********************************************************************************************************
PUBLIC CountLeadingZeros ;declare the below sub routine public
;so that it can be seen by the C compiler.
;(Similar to prototyping C functions in .h files)
;********************************************************************************************************
; Count Leading Zero's
;
; Description : This routine is called from OS_CPU_IRQ_ISR_Handler and
; OS_CPU_FIQ_ISR_Handler (bsp.c) in order to quickly
; determine the bit position of most significant '1' in
; a given 32 bit value
;
; Arguments : A 32 bit value ('data') that is to have its leading zero's
; counted (High order to Low order). This value arrives in
; register R0
;
; Returns : A 32 bit value ('ret_val') representing the number of zeros
; found present before reaching the most significant set bit in
; 'data' (Counting from high order to low order). This result
; is stored in register R1, but copied to, and returned from R0.
;
; Ex: If Bit 5 is set, then 'ret_val' would equal 0x1A,
; meaning there are 26 leading zero's before bit 5.
; OR (31 minus bit 5 = 26). Note: Zero set bits will
; return 32. So the above 31-bit formula doesnt work
; for the case when no bits are set.
;
; Notes : This sub routine should be prototyped in a .c or .h file
; as follows:
;
; extern INT32U CountLeadingZeros(INT32U val);
;
; Example : From C code, this routine may be called as follows:
;
; INT32U leading_zeros;
;
;
; leading_zeros = CountLeadingZeros(val);
;********************************************************************************************************
CountLeadingZeros:
CLZ R1,R0 ;Perform the count leading zero's operation
MOV R0, R1 ;Copy the return data to R0.
BX LR ;Return to the calling function
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -