VirtualBox

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

Last change on this file since 60756 was 60484, checked in by vboxsync, 9 years ago

PCBIOS: split up the support.asm file and implemented 32-bit division for pre-386 targets in C using uint32.h (derived from uint128.h via uint64.h).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
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;*******************************************************************************
31public _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
60next_bit:
61 shl cx, 1
62 jc return
63 dec ax
64 jmp next_bit
65
66return_zero:
67 xor ax, ax
68return:
69 pop bp
70 ret
71_ASMBitLastSetU16 endp
72
73_TEXT ends
74 end
75
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