Last change
on this file since 61025 was 61025, checked in by vboxsync, 9 years ago |
copyright header fix
|
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.8 KB
|
Line | |
---|
1 | ; $Id: ASMBitLastSetU16.asm 61025 2016-05-18 07:50:04Z 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 |
|
---|
18 |
|
---|
19 | ;*******************************************************************************
|
---|
20 | ;* Header Files *
|
---|
21 | ;*******************************************************************************
|
---|
22 | public _ASMBitLastSetU16
|
---|
23 |
|
---|
24 | .8086
|
---|
25 |
|
---|
26 | _TEXT segment public 'CODE' use16
|
---|
27 | assume cs:_TEXT
|
---|
28 |
|
---|
29 |
|
---|
30 | ;;
|
---|
31 | ; Finds the last bit which is set in the given 16-bit integer.
|
---|
32 | ;
|
---|
33 | ; Bits are numbered from 1 (least significant) to 16.
|
---|
34 | ;
|
---|
35 | ; @returns (ax) index [1..16] of the last set bit.
|
---|
36 | ; @returns (ax) 0 if all bits are cleared.
|
---|
37 | ; @param u16 Integer to search for set bits.
|
---|
38 | ;
|
---|
39 | ; @cproto DECLASM(unsigned) ASMBitLastSetU16(uint32_t u16);
|
---|
40 | ;
|
---|
41 | _ASMBitLastSetU16 proc
|
---|
42 | .8086
|
---|
43 | push bp
|
---|
44 | mov bp, sp
|
---|
45 |
|
---|
46 | mov cx, [bp + 2 + 2]
|
---|
47 | test cx, cx ; check if zero (eliminates checking dec ax result)
|
---|
48 | jz return_zero
|
---|
49 |
|
---|
50 | mov ax, 16
|
---|
51 | next_bit:
|
---|
52 | shl cx, 1
|
---|
53 | jc return
|
---|
54 | dec ax
|
---|
55 | jmp next_bit
|
---|
56 |
|
---|
57 | return_zero:
|
---|
58 | xor ax, ax
|
---|
59 | return:
|
---|
60 | pop bp
|
---|
61 | ret
|
---|
62 | _ASMBitLastSetU16 endp
|
---|
63 |
|
---|
64 | _TEXT ends
|
---|
65 | end
|
---|
66 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.