title: Write a program to compute factorial of an integer in ARM assembly language
body: <p>Given an integer I have to write a function that returns its factorial value.</p>
  
  <p>Here's my code for the factorial function:</p>
  
  <pre><code>bl getnum
  
  move r3, r0
  
  mov r1, #1   -- counter
  
  mov r4, r0
  
  
  loop:
     sub r0, r0, #1
  
     mul r3, r0, r3
  
     add r1, r1, #1  
  
     subs r1, r4  -- check if counter = the initial r0
  beg loop
  
  mov r0, r3
  
  bl printnum
  </code></pre>
  
  <p>However, this code yields incorrect result. For example when I input 5 it gives 20 instead of 120. Can someone help me find where things go wrong? My logical reasoning seems to work but I don't know whether I made a syntax error that causes the program to run in a different way</p>