VirtualBox

source: vbox/trunk/src/VBox/Devices/BiosCommonCode/ASMBitLastSetU16.asm@ 96586

Last change on this file since 96586 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1; $Id: ASMBitLastSetU16.asm 96407 2022-08-22 17:43:14Z vboxsync $
2;; @file
3; BiosCommonCode - ASMBitLastSetU16() - borrowed from IPRT.
4;
5
6;
7; Copyright (C) 2006-2022 Oracle and/or its affiliates.
8;
9; This file is part of VirtualBox base platform packages, as
10; available from https://www.virtualbox.org.
11;
12; This program is free software; you can redistribute it and/or
13; modify it under the terms of the GNU General Public License
14; as published by the Free Software Foundation, in version 3 of the
15; License.
16;
17; This program is distributed in the hope that it will be useful, but
18; WITHOUT ANY WARRANTY; without even the implied warranty of
19; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20; General Public License for more details.
21;
22; You should have received a copy of the GNU General Public License
23; along with this program; if not, see <https://www.gnu.org/licenses>.
24;
25; SPDX-License-Identifier: GPL-3.0-only
26;
27
28
29;*******************************************************************************
30;* Header Files *
31;*******************************************************************************
32public _ASMBitLastSetU16
33
34 .8086
35
36_TEXT segment public 'CODE' use16
37 assume cs:_TEXT
38
39
40;;
41; Finds the last bit which is set in the given 16-bit integer.
42;
43; Bits are numbered from 1 (least significant) to 16.
44;
45; @returns (ax) index [1..16] of the last set bit.
46; @returns (ax) 0 if all bits are cleared.
47; @param u16 Integer to search for set bits.
48;
49; @cproto DECLASM(unsigned) ASMBitLastSetU16(uint32_t u16);
50;
51_ASMBitLastSetU16 proc
52 .8086
53 push bp
54 mov bp, sp
55
56 mov cx, [bp + 2 + 2]
57 test cx, cx ; check if zero (eliminates checking dec ax result)
58 jz return_zero
59
60 mov ax, 16
61next_bit:
62 shl cx, 1
63 jc return
64 dec ax
65 jmp next_bit
66
67return_zero:
68 xor ax, ax
69return:
70 pop bp
71 ret
72_ASMBitLastSetU16 endp
73
74_TEXT ends
75 end
76
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette