当前位置:网站首页>GNU assembly basic mathematical equations multiplication

GNU assembly basic mathematical equations multiplication

2020-11-10 08:45:00 osc_uie90flw

brief introduction

Multiplication is an important operation in integer operation . What's different from addition and subtraction is , Multiplication is not the same for signed and unsigned integer operators .

Use mul To perform an operation without sign

MUL The command is used to multiply two unsigned integers .MUL The multiplication is as follows :

mul source

among source It can be 8 Bit , It can also be 16 Bit , It can also be 32 Bit .
here source It's the multiplier , And the value of the multiplier comes from EAX register .

example :

.code32
.section .data
data1:
    .int 10
data2:
    .int 20
answer:
    .quad 0
output:
    .asciz "The result is %qd\n"
.section .text
.globl _start
_start:
    nop
    movl data1,%eax
    mull data2
    movl %eax, answer
    movl %edx,answer+4
    pushl %edx
    pushl %eax
    pushl $output
    call printf
    add $12,%esp
    pushl $0
    call exit
as -o multest.o multest.s -gstabs --32
ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o multest -L/lib -lc multest.o

The result is finally put in EDX and EAX Combined 8 Byte content , among EDX It's the high place where the results are stored ,EAX The low position of the result .

Use imul Do signed operations

版权声明
本文为[osc_uie90flw]所创,转载请带上原文链接,感谢