# division two integer numbers

Status
Not open for further replies.

#### tryingsth

##### Junior Member level 2
Hello,
I try to divide 2 unsigned number with this code(below).but output is always 0. Output must be integer for my code. For ex. 156/10 returns 0, but I want to get 15. how can I solve this? Please help.

function divide (a : UNSIGNED; b : UNSIGNED) return UNSIGNED is
variable a1 : unsigned(a'length-1 downto 0):=a;
variable b1 : unsigned(b'length-1 downto 0):=b;
variable p1 : unsigned(b'length downto 0):= (others => '0');
variable i : integer:=0;

begin
for i in 0 to b'length-1 loop
p1(b'length-1 downto 1) := p1(b'length-2 downto 0);
p1(0) := a1(a'length-1);
a1(a'length-1 downto 1) := a1(a'length-2 downto 0);
p1 := p1-b1;
if(p1(b'length-1) ='1') then
a1(0) :='0';
p1 := p1+b1;
else
a1(0) :='1';
end if;
end loop;
return a1;

end divide;

Hello,
I try to divide 2 unsigned number with this code(below).but output is always 0. Output must be integer for my code. For ex. 156/10 returns 0, but I want to get 15. how can I solve this? Please help.

Use a simulator and step through the code. That is the best way to debug a problem.

Kevin Jennings

Status
Not open for further replies.