加法:
.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
减法:
.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
乘法:
1.mul 指令只能用于无符号整数:
.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 可用于带符号和无符号整数:
imul des ( AL,AX,EAX 中为隐含操作数,乘积结果被存放在 AX寄存器 or DX : AX 寄存器对 or EDX : EAX 寄存器对中 )
imul src, des ( src 可以是 16 or 32 位的寄存器 or 内存中, des 必须是 16 or 32 位的通用寄存器 )imul multi, src, des ( multi 与 src 的快速乘法的结果存放在 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
除法:
1.无符号除法
被除数 | 被除数长度 | 商 | 余数 |
AX | 16位 | AL | AH |
DX : AX | 32位 | AX | DX |
EDX : EAX | 64位 | 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.带符号除法 idiv divisor 类似
原文地址:http://blog.csdn.net/pandora_madara/article/details/40789399