1 | ; $Id: ASMBitLastSetU16.asm 60484 2016-04-14 09:25:51Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BiosCommonCode - ASMBitLastSetU16() - borrowed from IPRT.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2016 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 | ; The contents of this file may alternatively be used under the terms
|
---|
18 | ; of the Common Development and Distribution License Version 1.0
|
---|
19 | ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | ; VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | ; CDDL are applicable instead of those of the GPL.
|
---|
22 | ;
|
---|
23 | ; You may elect to license modified versions of this file under the
|
---|
24 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | ;
|
---|
26 |
|
---|
27 |
|
---|
28 | ;*******************************************************************************
|
---|
29 | ;* Header Files *
|
---|
30 | ;*******************************************************************************
|
---|
31 | public _ASMBitLastSetU16
|
---|
32 |
|
---|
33 | .8086
|
---|
34 |
|
---|
35 | _TEXT segment public 'CODE' use16
|
---|
36 | assume cs:_TEXT
|
---|
37 |
|
---|
38 |
|
---|
39 | ;;
|
---|
40 | ; Finds the last bit which is set in the given 16-bit integer.
|
---|
41 | ;
|
---|
42 | ; Bits are numbered from 1 (least significant) to 16.
|
---|
43 | ;
|
---|
44 | ; @returns (ax) index [1..16] of the last set bit.
|
---|
45 | ; @returns (ax) 0 if all bits are cleared.
|
---|
46 | ; @param u16 Integer to search for set bits.
|
---|
47 | ;
|
---|
48 | ; @cproto DECLASM(unsigned) ASMBitLastSetU16(uint32_t u16);
|
---|
49 | ;
|
---|
50 | _ASMBitLastSetU16 proc
|
---|
51 | .8086
|
---|
52 | push bp
|
---|
53 | mov bp, sp
|
---|
54 |
|
---|
55 | mov cx, [bp + 2 + 2]
|
---|
56 | test cx, cx ; check if zero (eliminates checking dec ax result)
|
---|
57 | jz return_zero
|
---|
58 |
|
---|
59 | mov ax, 16
|
---|
60 | next_bit:
|
---|
61 | shl cx, 1
|
---|
62 | jc return
|
---|
63 | dec ax
|
---|
64 | jmp next_bit
|
---|
65 |
|
---|
66 | return_zero:
|
---|
67 | xor ax, ax
|
---|
68 | return:
|
---|
69 | pop bp
|
---|
70 | ret
|
---|
71 | _ASMBitLastSetU16 endp
|
---|
72 |
|
---|
73 | _TEXT ends
|
---|
74 | end
|
---|
75 |
|
---|