At&t compiles basic mathematical functions

Source: Internet
Author: User
Tags mathematical functions


Addition:

. Section. Data
VAL:

. Quad 3481219651

Val1:

. Quad 6678934517

Output:

. Asciz "the RES is % QD \ n"


. Section. Text
. Globl _ start

_ Start:

Movl Val, % eax

Movl Val + 4, % EBX


Movl val1, % ECx

Movl val1 + 4, % edX


Addl % eax, % ECx

Adcl % EBX, % edX


Pushl % edX

Pushl % ECx

Pushl $ output

Call printf


Movl $1, % eax

Movl $0, % EBX

Int $0x80



Subtraction:

. Section. Data
VAL:

. Quad 3481219651

Val1:

. Quad 6678934517

Output:

. Asciz "the RES is % QD \ n"


. Section. Text
. Globl _ start
_ Start:

Movl val1, % eax

Movl val1 + 4, % EBX


Movl Val, % ECx

Movl Val + 4, % edX


Subl % eax, % ECx

Sbbl % EBX, % edX


Pushl % edX

Pushl % ECx

Pushl $ output

Call printf


Movl $1, % eax

Movl $0, % EBX

Int $0x80



Multiplication:

1. The Mul command can only be used for unsigned integers:

. Section. Data
VAL:

. Int 316722

Val1:

. Int 129907

Result:

. Quad 0

Output:

. Asciz "the RES is % QD \ n"


. Section. Text
. Globl _ start
_ Start:

Movl Val, % eax

Mull val1


Movl % eax, result

Movl % edX, result + 4


Pushl result + 4

Pushl result

Pushl $ output

Call printf


Movl $1, % eax

Movl $0, % EBX

Int $0x80


2. imul can be used for signed and unsigned integers:

Imul des (Al, ax, eax is the implicit operand, and the product result is stored in the ax register or DX: ax register pair or edX: eax register pair)

Imul SRC, des (SRC can be a 16 or 32-bit register or memory, des must be a 16 or 32-bit general-purpose register)

Imul multi, SRC, des (the result of rapid multiplication between Multi and SRC is stored in des)


. Section. Data
VAL:

. Int 10

Val1:

. Int 12

Val2:

. Int 100

Output:

. Asciz "the RES is % QD \ n"


. Section. Text
. Globl _ start
_ Start:

Movl Val, % eax

Movl val1, % EBX

Imull % eax, % EBX


Movl val2, % edX

Imull $4, % edX, % ECx


Movl $1, % eax

Movl $0, % EBX

Int $0x80


Division:

1. Unsigned Division

Divisor Divisor Length Vendors Remainder
Ax 16-bit Al Ah
DX: ax 32-bit Ax DX
EdX: eax 64-bit Eax EdX

Div Divisor


. Section. Data
Dividend:

. Quad 4537124

Divisor:

. Int 35

Quotient:

. Int 0

Remainder:

. Int 0

Output:

. Asciz "quotient is % d, remainder is % d \ n"


. Section. Text
. Globl _ start
_ Start:

Movl dividend, % eax

Movl dividend + 4, % edX


Divl Divisor


Movl % eax, quotient

Movl % edX, remainder


Pushl Remainder

Pushl quotient

Pushl $ output

Call printf


Addl $12, % ESP


Movl $1, % eax

Movl $0, % EBX

Int $0x80


2. The idiv divisor division with symbols is similar


At&t compiles basic mathematical functions

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.