title: How to print out two variables in assembly language?
body: <p>For my program, it will asks user to key in a positive number and it will subsequently do the double factorial calculation and print out the result. However, what I currently have is that the output will be printed out as &quot;Result = 15&quot; when I keyed in 5. I want to print the output as &quot;Result of 5 = 15&quot;. How can I do it?</p>
  <hr />
  <pre><code>.global main                @ start of the assembly code
  
  main:
      
      PUSH {LR}
      BL _getInput
      BL _calculate
      BL _output
  
      POP {PC}
  
  _getInput:
      
      PUSH {LR}
      BL _displayPrompt
  
      SUB SP, SP, #4          @ create word on stack
  
      LDR R0, addr_format     @ get the address of the the input entered by user
      MOV R1, SP              @ copy as parameter
      BL scanf
  
      LDR R1, [SP]            @ load the data from memory address of SP into R1
      LDR R2, addr_iterations @ load the address of iterations into R2
      STR R1, [R2]            @ store data from R1 into iterations
      ADD SP, SP, #4
  
      POP {PC}
  
  _displayPrompt:
      
      PUSH {LR}
      LDR R0, =prompt
  
      BL printf
  
      POP {PC}
  
  _calculate:
      
      LDR R0, addr_product
      LDR R0, [R0]
      LDR R1, addr_iterations
      LDR R1, [R1]                    @ Load the iteration counter
      MUL R0, R0, R1                  @ R0 *= R1 / product = product * counter
      SUBS R1, R1, #2             @ R1-- / counter = counter - 1
  
      LDR R2, addr_iterations         @ write back
      LDR R3, addr_product            @ address of where to store the result
      STR R0, [R3]                    @ store the final product back into addr_product
      STR R1, [R2]                    
  
      MOVLE PC, LR                    @ go back to main once the variable interations is 0 / return
      BGT _calculate                  @ continue looping as long as not 0
  
      
  _output:
      
      PUSH {LR}
      LDR R0, addr_message
      LDR R1, addr_product
      LDR R1, [R1]
  
      BL printf
  
      POP {PC}
  
  addr_format: .word scanformat
  
  addr_iterations: .word iterations
  
  addr_product: .word product
  
  addr_message: .word message
  
  .data
  
      prompt: .asciz &quot;Enter a positive integer number: &quot;
      scanformat: .asciz &quot;%d&quot;
      iterations: .word 1
      product: .word 1
      message: .asciz &quot;Result: %d\n&quot;
  </code></pre>