整数运算
- 加法
- 加法指令
add source, destination
- 示例
# addtest1.s - An example of the ADD instruction
.section .data
data:
.int 40
.section
.globl _start
_start:
nop
movl $0, %eax
movl $0, %ebx
movl $0, %ecx
movb $20, %al
addb $10, %al
movsx %al, %eax
movw $100, %cx
addw %cx, %bx
movsx %bx, %ebx
movl $100, %edx
addl %edx, %edx
addl data, %eax
addl %eax, data
movl $1, %eax
movl $0, %ebx
int $0x80
# addrest.s - An example of detecting a carry condition
.section .text
.globl _start
_start:
nop
movl $0, %eax
movb $190, %bl
movb $100, %al
addb %al, %bl
jc over
movl $1, %eax
int $0x80
over:
movl $1, %eax
movl $0, %ebx
int $0x80
* ADC 指令
* 格式
adc source, destination
* 示例
# addtest.s - An example of using the ADC instruction
.section .data
data1:
.quad 7252051615
data2:
.quad 5732348928
output:
.asciz "The result is %qd\n"
.section .text
.globl _start
_start:
movl data1, %ebx
movl data1+4, %eax
movl data2, %edx
movl data2+4, %ecx
addl %ebx, edx
adcl %eax, %ecx
pushl %ecx
pushl %edx
push $output
call printf
add $12, %esp
pushl $0
call exit
- 减法
- 减法指令
- 格式
sub source, destionation
- 示例
# subtest.s - An example of the SUB instruction
.section .data
data:
.int 40
.section .text
.globl _start
_start:
nop
movl $0, %eax
movl $0, %ebx
movl $0, %ecx
movb $20,