title: Convert hanoi problem C code to MIPS Assembly
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void move(int id, char from, char to){
      printf(&quot;move disk %d from %c to %c\n&quot;, id, from, to);
  }
  void hanoi(int base, char from, char via, char to){
      if (base == 0){
          move (base,from,via);
          move (base,via,to);
          return;
      }
      
      hanoi(base-1,from,via,to);
      move(base,from,via);
      hanoi(base-1,to,via,from);
      move(base,via,to);
      hanoi(base-1,from,via,to);
  }
  int main(){
      int n;
      scanf(&quot;%d&quot;,&amp;n);
      hanoi(n,'A','B','C');
      return 0;
  }
  </code></pre>
  <p>I have to make this hanoi problem C code to MIPS assembly language not using .global main.
  I've already done with normal hanoi problem as below, but that code above,It has a new rule which is can only move one block to the side. for example: A-&gt;B is ok, B-&gt;C is ok, but A-&gt;C cannot, C-&gt;A cannot. I really don't know how to convert it, I'm doing this for few days, Need help</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  void dfs(int n,char from,char via,char to);
  int main() {
      int n;
      char from='A',via='B',to='C';
      scanf(&quot;%d&quot;,&amp;n);
      dfs(n,from,via,to);
      
      return 0;
  }
  void dfs(int n,char from,char via,char to){
      if(n==1){
          printf(&quot;%c --&gt; %c\n&quot;,from,to);
          return;
      }
      dfs(n-1,from,to,via);
      dfs(1,from,via,to);
      dfs(n-1,via,from,to);
      return;
  }
  
  
  .data
  connect: .asciiz &quot;--&gt;&quot;
  enter: .asciiz &quot;\n&quot;
  _a: .asciiz &quot;A&quot;
  _b: .asciiz &quot;B&quot;
  _c: .asciiz &quot;C&quot;
  
  .macro save(%a)
      sw %a,($sp)
      addi $sp,$sp,-4
  .end_macro
  
  .macro swap(%a,%b)
      move $t0,%a
      move %a,%b
      move %b,$t0
  .end_macro
  
  .macro load(%a)
      addi $sp,$sp,4
      lw %a,($sp)
  .end_macro
  
  
  .text
      li $v0,5
      syscall 
      move $s0,$v0 # s0 == n
      move $a0,$v0 
      la $a1,_a # A ~ from
  
      la $a2,_b # B ~ tmp
      la $a3, _c # C ~ to
      jal dfs
      
      li $v0, 10
      syscall 
      
  dfs:  # A --&gt; C or $a1 --&gt; $a3
      bgt $a0,1,dfs_work # if $a0 &gt; 1  == if n == 1
      move $a0, $a1 # A
      li $v0,4 # print string
      syscall 
      la $a0, connect # --&gt;
      li $v0,4 # C
      syscall 
      move $a0,$a3
      li $v0,4
      syscall 
      la $a0,enter # enter
      li $v0,4
      syscall 
      jr $ra
      
      
  dfs_work:
      save($ra) # save address
      save($a0) # current n
      save($a1) # A
      save($a2) # B
      save($a3) # C
      addi $a0,$a0,-1
      swap ($a2,$a3) # A C B
      jal dfs
      load($a3)
      load($a2)
      load($a1)
      load($a0)
      load($ra)
      
      save($ra)
      save($a0)
      save($a1)
      save($a2)
      save($a3)
      li $a0,1
      jal dfs
      load($a3)
      load($a2)
      load($a1)
      load($a0)
      load($ra)
      
      save($ra)
      save($a0)
      save($a1)
      save($a2)
      save($a3)
      addi $a0,$a0,-1
      swap($a1,$a2)
      jal dfs
      
      load($a3)
      load($a2)
      load($a1)
      load($a0)
      load($ra)
      
      jr $ra
  </code></pre>
  <p>I tried my best to solve it, but didnt make it. need some help</p>