Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INP //Take input A...
- STA INPUTA //...and store it
- INP //Take input B...
- STA INPUTB //...and store it
- SUB INPUTA //Subtract A from B in acc
- BRP AISBIGGEST //If result is 0 OR +ve, go to AISBIGGEST, else...:
- LDA INPUTA //Load A into acc
- STA DIVIDEND //Store it as biggest
- LDA INPUTB //Load B into acc
- STA DIVISOR //Store as smallest
- BRA STAGEC //Goto next stage
- AISBIGGEST LDA INPUTB //Result is +ve, so we've got to here
- LDA INPUTA //Load A into acc
- STA DIVISOR //Store as smallest
- LDA INPUTB //Load B into acc
- STA DIVIDEND //Store it as biggest
- STAGEC LDA ZERO //Iniatilize for Multiple Program Run
- STA QUOTIENT //Clear Any Previous Quotient
- STA REMAINDER //Clear Any Previous Remainder
- LDA DIVIDEND //Load Dividend
- SUB DIVISOR //Subtract Divisor
- STA RESULT //Store Result
- BRP LABELA //Skip To LABELA If Result is 0 or Positive
- ADD DIVISOR //Negative Result + Divisor...
- STA REMAINDER //...Equals Positive Remainder
- BRA QUIT //Done, Quotient is 0, Branch to QUIT
- LABELA LDA COUNTER //Load 1
- ADD QUOTIENT //Add 1 to Quotient
- STA QUOTIENT //Store New Quotient
- LDA RESULT //Load Result
- BRZ QUIT //If Zero, Done, Quotient is 1, Branch to QUIT
- LOOP LDA RESULT //Load Result
- SUB DIVISOR //Subtract Divisor
- STA RESULT //Store Result
- BRP LABELB //Skip To LABELB If Result Is Positive
- ADD DIVISOR //Negative Result + Divisor...
- STA REMAINDER //...Equals Positive Remainder
- BRA QUIT //Done, With Remainder, Branch to QUIT
- LABELB LDA COUNTER //Load 1
- ADD QUOTIENT //Add 1 to Quotient
- STA QUOTIENT //Store New Quotien
- OUT QUOTIENT //Output the answer
- LDA RESULT //Load Result
- BRZ QUIT //Result is 0, Done, No Remainder, Branch to QUIT
- BRA LOOP //More to Do - Go Back to LOOP
- QUIT HLT //HALT - Done!
- INPUTA DAT
- INPUTB DAT
- COUNTER DAT 001 //Counter with Constant Value of 1
- ZERO DAT 000 //Zero with Constant Value of 0
- RESULT DAT 000 //(Dividend - Divisor), Then (Result - Divisor)
- DIVIDEND DAT 000 //User Provided Dividend
- DIVISOR DAT 000 //User Provided Divisor
- QUOTIENT DAT 000 //Computed Quotient
- REMAINDER DAT 000 //Computed Remainder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement