title: In ARM Assembly, why are my values not updating?
body: <p>I am working on a simple ATM Machine. The issue I am having is:</p>
  
  <pre><code>        areFundsAvailable:
              cmp r8, r4
              ble fundsNotAvailable
              sub r8, r8, r4
  
      subtractTwenties:
              sub r4, r4, #20
              cmp r4, #10
              ble subtractTens
              sub r7, r7, #1
              b subtractTwenties
  
      subtractTens:
              cmp r4, #0
              beq withdrawComplete
              sub r4, #10
              b subtractTens
  </code></pre>
  
  <hr>
  
  <p>My Inventory:</p>
  
  <pre><code>getInventory:   
  push {r4, lr}
          ldr r5, =total  
          ldr r8, [r5]    
          ldr r5, =inventory20
          ldr r7, [r5]
          ldr r5, =inventory10    
          ldr r6, [r5]
          ldr r5, =transactionLimit
          ldr r9, [r5]
  
  sumTwenties:
          cmp r7, #0
          ble sumTens 
          add r8, r8, #20
          sub r7, r7, #1
          b sumTwenties               
  
  sumTens:        
          cmp r6, #0
          ble loopDone
          add r8, r8, #10
          sub r6, r6, #1
          b sumTens
  
          ldr r5, =total
          str r8, [r5]
  loopDone:
  
  
  pop {r4, pc}    
  </code></pre>
  
  <p>My Issue:</p>
  
  <p>I am asking a user to enter an amount to withdraw. The ATM is limited to maximum transactions in a session, holds a set value of 20 dollar bills and 10 dollar bills so eventually it can run out of money.</p>
  
  <p>I've done a good bit of the implementation, like making sure they only enter a value between 0-200, it's a multiple of 10. </p>
  
  <p>I also can call my secret code, which does display my current inventory.</p>
  
  <p>I am trying to work through my first transaction, by asking to withdraw, let's say $40. I need to make sure the withdrawal is approved, which works. Then I need to make sure I give them all 20s first, then 10s, if they selected a withdrawal like $50 for example.</p>
  
  <p>I am running GDB, and noticing the register which is storing the total value (1500) is getting updated and deducted (1460) but my registers that hold my 20s and 10s are displaying 0. </p>
  
  <p>This means I am not loading the registers or I am having some kind of issue I can't wrap my head around. 
  I've pasted some of the more important pieces of code to see if I could get some feedback.</p>
  
  <p>I do know this is an issue with me pushing and popping the stack, but I am getting lost.</p>
  
  <p>Edit:
  Register 7 has 50 20s by default
  Register 6 has 50 10s by default</p>
  
  <h2>Register 8 is the sum of 6 and 7 = 1500</h2>
  
  <p>Upon putting breakpoint
  My registers are showing:<br>
  R7 : 0<br>
  R6: 0<br>
  R8: 1460  </p>
  
  <p>I should be seeing</p>
  
  <p>R7: 48<br>
  R6: 50</p>
  
  <p>Second edit:  </p>
  
  <p>Putting a breakpoint on my function withdrawRequestApproved, I am noticing the value is holding the WithdrawInput correctly.</p>
  
  <pre><code>    withdrawRequestApproved:
          ldr r0, =amountRequested
          mov r1, r4
          bl printf
          bl getInventory
  
  checkTransactionLimit:
          add r9, r9, #1
          cmp r9, #10
          bgt transactionLimitReached
  
  
  areFundsAvailable:
          cmp r8, r4
          ble fundsNotAvailable
          sub r8, r8, r4
  </code></pre>
  
  <p>calling bl getInventory is loading my total, but I am not loading my 20s and 10s. Also, I am losing my register 4 value after this function as well.</p>