VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U4D.asm

Last change on this file was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1; $Id: bs3-wc16-U4D.asm 106061 2024-09-16 14:03:52Z vboxsync $
2;; @file
3; BS3Kit - 16-bit Watcom C/C++, 32-bit unsigned integer division.
4;
5
6;
7; Copyright (C) 2007-2024 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; The contents of this file may alternatively be used under the terms
26; of the Common Development and Distribution License Version 1.0
27; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28; in the VirtualBox distribution, in which case the provisions of the
29; CDDL are applicable instead of those of the GPL.
30;
31; You may elect to license modified versions of this file under the
32; terms and conditions of either the GPL or the CDDL or both.
33;
34; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35;
36
37%include "bs3kit-template-header.mac"
38
39
40
41;;
42; 32-bit unsigned integer division.
43;
44; @returns DX:AX quotient, CX:BX remainder.
45; @param DX:AX Dividend.
46; @param CX:BX Divisor
47;
48; @uses Nothing.
49;
50%ifdef BS3KIT_WITH_REAL_WATCOM_INTRINSIC_NAMES
51global __U4D
52__U4D:
53%endif
54global $_?U4D
55$_?U4D:
56%if TMPL_BITS >= 32
57 ; Move dividend into EDX:EAX
58 shl eax, 10h
59 mov ax, dx
60 xor edx, edx
61
62 ; Move divisor into ebx.
63 shl ebx, 10h
64 mov bx, cx
65
66 ; Do it!
67 div ebx
68
69 ; Reminder in to CX:BX
70 mov bx, dx
71 shr edx, 10h
72 mov cx, dx
73
74 ; Quotient into DX:AX
75 mov edx, eax
76 shr edx, 10h
77%else
78 push ds
79 push es
80
81 ;
82 ; Convert to a C __cdecl call - too lazy to do this in assembly.
83 ;
84
85 ; Set up a frame of sorts, allocating 8 bytes for the result buffer.
86 push bp
87 sub sp, 08h
88 mov bp, sp
89
90 ; Pointer to the return buffer.
91 push ss
92 push bp
93 add bp, 08h ; Correct bp.
94
95 ; The divisor.
96 push cx
97 push bx
98
99 ; The dividend.
100 push dx
101 push ax
102
103 BS3_EXTERN_CMN Bs3UInt32Div
104 call Bs3UInt32Div
105
106 ; Load the reminder.
107 mov cx, [bp - 08h + 6]
108 mov bx, [bp - 08h + 4]
109 ; Load the quotient.
110 mov dx, [bp - 08h + 2]
111 mov ax, [bp - 08h]
112
113 mov sp, bp
114 pop bp
115 pop es
116 pop ds
117
118%endif
119%ifdef ASM_MODEL_FAR_CODE
120 retf
121%else
122 ret
123%endif
124
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