Assembly--Arithmetic operation class instruction

Source: Internet
Author: User
Tags mul microsoft dynamics

Addition instructions: Add, ADC, INC

Subtraction directives: SUB, SBB, DEC, NEG, CMP

Multiplication instruction: MUL, Imul

Division instruction: DIV, Idiv

Decimal Adjustment directives: DAA, DAS, AAA, AAS, AAM, AAD

Addition instruction: ADD

Carry addition instruction: ADC

Add a directive: INC

Note: Except that the INC directive does not affect the CF mark, it has an effect on the condition mark.

The result is 0 zf=1 the result is negative sf=1

The CF bit represents an overflow of unsigned number additions. The most significant bit of the and has the carry to the high

The of bit represents an overflow with a signed number addition.

    • Two operand symbols are the same, and the result symbol is the opposite
    • Two operand symbols opposite, and the result symbol is the same as the meiosis

Subtraction directive: SUB (Subtract)

With borrow subtraction directive: SBB SBB commands are combined with sub to achieve multi-precision subtraction operations

Minus one instruction: DEC (decrement)

The command: NEG OPR calculation can also be expressed as: the operand is reversed after adding 1, forget to add 1.

Comparison directive: CMP OPR1,OPR2

The INC directive and the DEC Directive are single-operand directives that are used primarily to adjust counter and address pointers

The effect of NEG instruction on cf/of

    • The operand is 0 cf=0 otherwise 1
    • Operand is-128 (byte operation) or operand is-32768 (word arithmetic) of=1 otherwise 1

The CMP instruction performs the same function as the Sub directive, but the result does not echo the destination operand

Unsigned number multiplication directive: MUL

Signed number multiplication directive: Imul

Unsigned number multiplication directive: MUL SRC performs the operation:

    • byte operand (AX)? (AL) * (SRC)
    • Word operand (DX, AX)? (AX) * (SRC)

Signed number multiplication directive: Imul SRC

The multiplication instruction uses the and CF to determine whether the high half of the product has a valid value

Mul Instruction--If the product is half high (ah or DX) is 0, then of=cf=0; otherwise of=cf=1

Imul Instruction--if the high half of the product is the symbol extension of the lower half, then the of=cf=0; otherwise 1

Multiplication directives are not defined for other status identifiers

There is no definition for flags: These flags are arbitrary and unpredictable after the instruction is executed (that is, no one knows whether it is 0 or 1)

No effect on flags: instruction execution does not change flag status

Division

The div is the unsigned number division Div, which divides the two unsigned numbers.

The Idiv is a signed number division instruction that accomplishes two signed numbers to divide.

Unsigned number Division instruction: DIV SRC performs the operation:

Byte operation: (AL)? (AX)/(SRC)

(AH)? remainder of (AX)/(SRC)

Word manipulation: (AX)? (DX, AX)/(SRC) business

(DX)? Remainder of (DX, AX)/(SRC)

Signed Number Division instruction: Idiv SRC

Attention:

    • Ax (DX, Ax) is an implied dividend register.
    • AL (AX) is the implied quotient register.
    • AH (DX) is the implied remainder register.
    • SRC cannot be an immediate number.
    • There is no definition for all the conditional flag bits.

The division instruction does not define a division instruction to the flag, which results in overflow

The Division error interrupt dividend is much larger than the divisor, resulting in an overflow numbered 0.

Decimal Adjustment Directives

Decimal number adjustment Instruction decimal adjustment of the result of binary operation to get the result of decimal operation

Divided into compressed BCD code and non-compressed BCD code adjustment

The compressed BCD code is the usual 8421 yards; it uses 4 bits to represent a decimal bit, and one byte can represent two decimal digits, i.e. 00~99

The non-compressed BCD code uses 8 bits to represent a decimal bit, with a low 4 bits representing a decimal bit 0~9, a height of 4 bits, and a default of 0 resulting in waste .

Compressed BCD code adjustment directive: DAA, DAS

Non-compressed BCD code adjustment directives: AAA, AAS, AAM, AAD

DAA; al← The addition and adjustment of AL to the compressed BCD code

DAS; al← to adjust the reduction of AL to a compressed BCD code and borrow 1?

Before using the DAA or DAS instructions, you should perform an addition or subtraction instruction for the operand of al

The DAA and Das directives have no definition of the of flag and affect other flags by result, such as CF reflects the rounding or borrow state of the condensed BCD code addition or subtraction

Add AL,BL; binary addition: al=68h+28h=90h

DAA; Decimal adjustment: al=96h

Sub al,bl; Binary subtraction: al=68h-28h=40h

Das; Decimal adjustment: al=40h

Das; 34-12=22,cf=0

Das; 12-46=66,cf=1

AAA; al← the addition and adjustment of AL to non-compressed BCD code; ah←ah+ Adjusted rounding

AAS; al← to adjust the difference of AL to non-compressed BCD code; ah←ah-Adjustment Borrow

Before using the AAA or AAS directives, you should perform an addition or subtraction instruction with the operand of Al as the first

The AAA and AAS directives produce a carry or borrow in the adjustment, and AH is to add carry or subtract borrow, while cf=af=1, otherwise cf=af=0; they have no definition of other flags

mov ax,0608h; ax=0608h, non-compressed BCD denotes true truth 68

mov bl,09h; bl=09h, non-compressed BCD denotes true truth 9

Add AL,BL; binary addition: al=08h+09h=11h

AAA; decimal adjustment: ax=0707h; implementing non-compressed BCD code addition: 68+9=77

Sub al,bl; Binary subtraction: AL=08H-09H=FFH

AAS; decimal adjustment: ax=0509h; implementing non-compressible BCD code subtraction: 68-9=59

AAM; ax← to adjust the product of AX to non-compressed BCD code

ax← to expand the non-compressed BCD code in Microsoft Dynamics AX into a binary number

    • AAM instruction follows the byte multiply Mul, the product is adjusted to non-compressed BCD code
    • The AAD command moves the dividend of the uncompressed BCD code to a binary number before the byte is in addition to the Div.
    • AAM and AAD instructions set SF, ZF, and PF based on results, but no definition for of, CF, and AF

Mul bl; binary multiplication: al=08hx09h=0048h

AAM; decimal adjustment: ax=0702h; implementing non-compressible BCD code multiplication: 8x9=72

AAM; binary extension: ax=68=0044h

div BL; Division operation: Quotient al=07h, remainder ah=05h; realization of non-compressed BCD initial method: 68÷9=7 (remainder 5)

Assembly--Arithmetic operation class instruction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.