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