Advertisement
rakiru

LMC Divide Largest By Smallest, Output Quotient

May 14th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. INP //Take input A...
  2. STA INPUTA //...and store it
  3. INP //Take input B...
  4. STA INPUTB //...and store it
  5.  
  6. SUB INPUTA //Subtract A from B in acc
  7. BRP AISBIGGEST //If result is 0 OR +ve, go to AISBIGGEST, else...:
  8. LDA INPUTA //Load A into acc
  9. STA DIVIDEND //Store it as biggest
  10. LDA INPUTB //Load B into acc
  11. STA DIVISOR //Store as smallest
  12. BRA STAGEC //Goto next stage
  13.  
  14. AISBIGGEST LDA INPUTB //Result is +ve, so we've got to here
  15. LDA INPUTA //Load A into acc
  16. STA DIVISOR //Store as smallest
  17. LDA INPUTB //Load B into acc
  18. STA DIVIDEND //Store it as biggest
  19.  
  20. STAGEC LDA ZERO //Iniatilize for Multiple Program Run
  21. STA QUOTIENT //Clear Any Previous Quotient
  22. STA REMAINDER //Clear Any Previous Remainder
  23. LDA DIVIDEND //Load Dividend
  24. SUB DIVISOR //Subtract Divisor
  25. STA RESULT //Store Result
  26. BRP LABELA //Skip To LABELA If Result is 0 or Positive
  27. ADD DIVISOR //Negative Result + Divisor...
  28. STA REMAINDER //...Equals Positive Remainder
  29. BRA QUIT //Done, Quotient is 0, Branch to QUIT
  30. LABELA LDA COUNTER //Load 1
  31. ADD QUOTIENT //Add 1 to Quotient
  32. STA QUOTIENT //Store New Quotient
  33. LDA RESULT //Load Result
  34. BRZ QUIT //If Zero, Done, Quotient is 1, Branch to QUIT
  35. LOOP LDA RESULT //Load Result
  36. SUB DIVISOR //Subtract Divisor
  37. STA RESULT //Store Result
  38. BRP LABELB //Skip To LABELB If Result Is Positive
  39. ADD DIVISOR //Negative Result + Divisor...
  40. STA REMAINDER //...Equals Positive Remainder
  41. BRA QUIT //Done, With Remainder, Branch to QUIT
  42. LABELB LDA COUNTER //Load 1
  43. ADD QUOTIENT //Add 1 to Quotient
  44. STA QUOTIENT //Store New Quotien
  45. OUT QUOTIENT //Output the answer
  46. LDA RESULT //Load Result
  47. BRZ QUIT //Result is 0, Done, No Remainder, Branch to QUIT
  48. BRA LOOP //More to Do - Go Back to LOOP
  49.  
  50. QUIT HLT //HALT - Done!
  51.  
  52. INPUTA DAT
  53. INPUTB DAT
  54. COUNTER DAT 001 //Counter with Constant Value of 1
  55. ZERO DAT 000 //Zero with Constant Value of 0
  56. RESULT DAT 000 //(Dividend - Divisor), Then (Result - Divisor)
  57. DIVIDEND DAT 000 //User Provided Dividend
  58. DIVISOR DAT 000 //User Provided Divisor
  59. QUOTIENT DAT 000 //Computed Quotient
  60. REMAINDER DAT 000 //Computed Remainder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement