VirtualBox

source: vbox/trunk/src/VBox/Devices/BiosCommonCode/__U4D.asm@ 82968

Last change on this file since 82968 was 82968, checked in by vboxsync, 5 years 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.5 KB
Line 
1; $Id: __U4D.asm 82968 2020-02-04 10:35:17Z vboxsync $
2;; @file
3; Compiler support routines.
4;
5
6;
7; Copyright (C) 2012-2020 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;* Exported Symbols *
21;*******************************************************************************
22public __U4D
23
24 .8086
25
26if VBOX_BIOS_CPU lt 80386
27extrn _DoUInt32Div:near
28endif
29
30
31_TEXT segment public 'CODE' use16
32 assume cs:_TEXT
33
34
35;;
36; 32-bit unsigned division.
37;
38; @param dx:ax Dividend.
39; @param cx:bx Divisor.
40; @returns dx:ax Quotient.
41; cx:bx Remainder.
42;
43__U4D:
44 pushf
45if VBOX_BIOS_CPU ge 80386
46 .386
47 push eax
48 push edx
49 push ecx
50
51 rol eax, 16
52 mov ax, dx
53 ror eax, 16
54 xor edx, edx
55
56 shr ecx, 16
57 mov cx, bx
58
59 div ecx ; eax:edx / ecx -> eax=quotient, edx=remainder.
60
61 mov bx, dx
62 pop ecx
63 shr edx, 16
64 mov cx, dx
65
66 pop edx
67 ror eax, 16
68 mov dx, ax
69 add sp, 2
70 pop ax
71 rol eax, 16
72 .8086
73else
74 ;
75 ; If the divisor is only 16-bit, use a fast path
76 ;
77 test cx, cx
78 jnz do_it_the_hard_way
79
80 div bx ; dx:ax / bx -> ax=quotient, dx=remainder
81
82 mov bx, dx ; remainder in cx:bx, and we know cx=0
83
84 xor dx, dx ; quotient in dx:ax, dx must be zero
85
86 popf
87 ret
88
89do_it_the_hard_way:
90 ; Call C function do this.
91 push ds
92 push es
93
94 ;
95 ; Convert to a C __cdecl call - not doing this in assembly.
96 ;
97
98 ; Set up a frame of sorts, allocating 4 bytes for the result buffer.
99 push bp
100 sub sp, 04h
101 mov bp, sp
102
103 ; Pointer to the return buffer.
104 push ss
105 push bp
106 add bp, 04h ; Correct bp.
107
108 ; The divisor.
109 push cx
110 push bx
111
112 ; The dividend.
113 push dx
114 push ax
115
116 call _DoUInt32Div
117
118 ; Load the remainder.
119 mov cx, [bp - 02h]
120 mov bx, [bp - 04h]
121
122 ; The quotient is already in dx:ax
123
124 mov sp, bp
125 pop bp
126 pop es
127 pop ds
128endif
129 popf
130 ret
131
132_TEXT ends
133 end
134
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