1 /////////////////////////////////////////////////////////////////////////
2 // $Id: mult8.cc,v 1.31 2008/08/11 20:34:05 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2001 MandrakeSoft S.A.
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /////////////////////////////////////////////////////////////////////////
28 #define NEED_CPU_REG_SHORTCUTS 1
31 #define LOG_THIS BX_CPU_THIS_PTR
33 void BX_CPP_AttrRegparmN(1) BX_CPU_C::MUL_ALEbR(bxInstruction_c
*i
)
36 Bit8u op2
= BX_READ_8BIT_REGx(i
->rm(), i
->extend8bitL());
38 Bit32u product_16
= ((Bit16u
) op1
) * ((Bit16u
) op2
);
40 Bit8u product_8l
= (product_16
& 0xFF);
41 Bit8u product_8h
= product_16
>> 8;
43 /* now write product back to destination */
47 SET_FLAGS_OSZAPC_LOGIC_8(product_8l
);
50 ASSERT_FLAGS_OxxxxC();
54 void BX_CPP_AttrRegparmN(1) BX_CPU_C::IMUL_ALEbR(bxInstruction_c
*i
)
57 Bit8s op2
= BX_READ_8BIT_REGx(i
->rm(), i
->extend8bitL());
59 Bit16s product_16
= op1
* op2
;
60 Bit8u product_8
= (product_16
& 0xFF);
62 /* now write product back to destination */
66 * IMUL r/m8: condition for clearing CF & OF:
67 * AX = sign-extend of AL to 16 bits
70 SET_FLAGS_OSZAPC_LOGIC_8(product_8
);
71 if(product_16
!= (Bit8s
) product_16
)
73 ASSERT_FLAGS_OxxxxC();
77 void BX_CPP_AttrRegparmN(1) BX_CPU_C::DIV_ALEbR(bxInstruction_c
*i
)
79 Bit8u op2
= BX_READ_8BIT_REGx(i
->rm(), i
->extend8bitL());
81 exception(BX_DE_EXCEPTION
, 0, 0);
86 Bit16u quotient_16
= op1
/ op2
;
87 Bit8u remainder_8
= op1
% op2
;
88 Bit8u quotient_8l
= quotient_16
& 0xFF;
90 if (quotient_16
!= quotient_8l
)
92 exception(BX_DE_EXCEPTION
, 0, 0);
95 /* now write quotient back to destination */
100 void BX_CPP_AttrRegparmN(1) BX_CPU_C::IDIV_ALEbR(bxInstruction_c
*i
)
104 /* check MIN_INT case */
105 if (op1
== ((Bit16s
)0x8000))
106 exception(BX_DE_EXCEPTION
, 0, 0);
108 Bit8s op2
= BX_READ_8BIT_REGx(i
->rm(), i
->extend8bitL());
111 exception(BX_DE_EXCEPTION
, 0, 0);
113 Bit16s quotient_16
= op1
/ op2
;
114 Bit8s remainder_8
= op1
% op2
;
115 Bit8s quotient_8l
= quotient_16
& 0xFF;
117 if (quotient_16
!= quotient_8l
)
118 exception(BX_DE_EXCEPTION
, 0, 0);
120 /* now write quotient back to destination */