Advertisement
rakiru

LMC Divide Large by Small, Output Larger, Smallest, Quotient

May 14th, 2012
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 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 Quotient
  45. LDA RESULT //Load Result
  46. BRZ QUIT //Result is 0, Done, No Remainder, Branch to QUIT
  47. BRA LOOP //More to Do - Go Back to LOOP
  48.  
  49. QUIT OUT DIVIDEND //Output largest number
  50. OUT DIVISOR //Output smallest number
  51. OUT RESULT //Output result
  52. HLT //HALT - Done!
  53.  
  54. INPUTA DAT
  55. INPUTB DAT
  56. COUNTER DAT 001 //Counter with Constant Value of 1
  57. ZERO DAT 000 //Zero with Constant Value of 0
  58. RESULT DAT 000 //(Dividend - Divisor), Then (Result - Divisor)
  59. DIVIDEND DAT 000 //User Provided Dividend
  60. DIVISOR DAT 000 //User Provided Divisor
  61. QUOTIENT DAT 000 //Computed Quotient
  62. REMAINDER DAT 000 //Computed Remainder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement