Hardware Reference
In-Depth Information
The ediv instruction performs an unsigned 32-bit by 16-bit division. The dividend is the
register pair Y and D with Y as the upper 16 bits of the dividend. Index register X is the divisor.
After division, the quotient and the remainder are placed in Y and D, respectively.
The edivs instruction performs a signed 32-bit by 16-bit division using the same operands
as the ediv instruction. After division, the quotient and the remainder are placed in Y and D,
respectively.
The fdiv instruction divides an unsigned 16-bit dividend in double accumulator D by an un-
signed 16-bit divisor in index register X, producing an unsigned 16-bit quotient in X, and an un-
signed 16-bit remainder in D. The dividend must be less than the divisor. The radix point of the
quotient is to the left of bit 15. In the case of overflow (the denominator is less than or equal to the
nominator) or division by zero, the quotient is set to $FFFF and the remainder is indeterminate.
The idiv instruction divides an unsigned 16-bit dividend in double accumulator D by the
unsigned 16-bit divisor in index register X, producing an unsigned 16-bit quotient in X and an
unsigned 16-bit remainder in D. If both the divisor and the dividend are assumed to have ra-
dix points in the same positions (to the right of bit 0), the radix point of the quotient is to the
right of bit 0. In the case of division by zero, the quotient is set to $FFFF and the remainder is
indeterminate.
The idivs instruction divides the signed 16-bit dividend in double accumulator D by the
signed 16-bit divisor in index register X, producing a signed 16-bit quotient in X and a signed
16-bit remainder in D. If division by zero is attempted, the values in D and X are not changed,
but the values of the N, Z, and V status bits are undefined.
Example 2.10
Write an instruction sequence to multiply the contents of index register X and double ac-
cumulator D and store the product at memory locations $1000,$1003.
Solution: There is no instruction to multiply the contents of double accumulator D and index
register X. However, we can transfer the contents of index register X to index register Y and
execute the emul instruction. If index register Y holds useful information, then we need to save
it before the data transfer.
sty
$1010
; save Y in a temporary location
tfr
x,y
; transfer the contents of X to Y
emul
; perform the multiplication
sty
$1000
; save the upper 16 bits of the product
std
$1002
; save the lower 16 bits of the product
ldy
$1010
; restore the value of Y
Example 2.11
Write an instruction sequence to divide the signed 16-bit number stored at memory loca-
tions $1005,$1006 by the 16-bit signed number stored at memory locations $1020,$1021 and
store the quotient and remainder at $1030,$1031 and $1032,$1033, respectively.
Solution: Before we can perform the division, we need to place the dividend and divisor in D and
X, respectively.
 
Search WWH ::




Custom Search