Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @5
  2. D=A //D=5
  3. @i
  4. M=D
  5.  
  6. (LOOP)
  7. @i
  8. D=M
  9. @END
  10. D;JEQ
  11. @sum
  12. M=D+M
  13. @i
  14. M=M-1
  15. @LOOP
  16. 0;JMP
  17.  
  18. (END)
  19. @END
  20. 0;JMP
  21.  
  22. ------------------------
  23.  
  24. // Write the pseudocode for the algorithm on the left (Add  5+...+1).  Generally it compute the sum of a number from the upper bound (5) to the lower bound (1)
  25.  
  26. Declare and initialize counter  i
  27. Declare and initialize sum
  28.  
  29. Loop
  30. Load memory location i
  31. Assign value in I to Data
  32. Load memory location END
  33.          If Data is 0 then Jump to location END; if not continue next  intr
  34. Load memory location sum
  35. Add data (current value of i) to sum (memory of sum)
  36.          Load memory location i
  37. Decrease I by 1
  38. Load memory location LOOP
  39. Jump to LOOP to execute next round
  40.  
  41. END
  42.          Load memory location END
  43.          Jump until halt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement