Hello i am writing a x86 assembly code where i have to do a multiply function wi
ID: 3630615 • Letter: H
Question
Hello i am writing a x86 assembly code where i have to do a multiply function without using any multiply or divide instructions. Only shl I have all my cases working except for negative times negative.
This is my code so far
.intel_syntax noprefix
.data
.globl _x
_x: .long 0
.global _y
_y:
.text
.globl _fac
_fac:
push ebp
mov ebp,esp
mov eax,0
mov edx,1
mov ebx,_x
mov ecx,_y
cmp edx,ecx
jl LOOP
xchg ecx,ebx
LOOP:
cmp edx,ecx
jg DONE
add eax,ebx
SUB ecx,1
jmp LOOP
DONE:
pop ebp #you need this too
ret #return
It works with the following main.c file
#include <stdio.h>
extern int x, y;
extern int fac();
main()
{
x = -7;
y = -4;
printf("%d * %d = %d ",x,y,fac());
}