VirtualBox

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

Last change on this file since 78223 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • 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 76553 2019-01-01 01:45:53Z vboxsync $
2;; @file
3; BiosCommonCode - ASMBitLastSetU16() - borrowed from IPRT.
4;
5
6;
7; Copyright (C) 2006-2019 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;*******************************************************************************
22public _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
51next_bit:
52 shl cx, 1
53 jc return
54 dec ax
55 jmp next_bit
56
57return_zero:
58 xor ax, ax
59return:
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.

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