Question

Write a subroutine code to divide two positive numbers by repeated subtraction method. For exampl...

Write a subroutine code to divide two positive numbers by repeated subtraction method. For example, to divide 100 over 8 by subtracting 8 from 100 until the reminder be less than 8, then count the times of the subtractions, to give the result. The first number, second number, and then the result locations must follow the calling code.

I need the solution using assembly language not java or c++, please..!!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code in Marie will be:

    Input
    Store   A
    Input
    Store   B

Loop,   Load    A  
    Subt    B
    Store   A
    Skipcond 800
    Jump    Endloop
    Load    X
    Add     One
    Store   X
    Jump Loop

IncrementX, Load    X
    Add     One
    Store   X
    Load    A
    Subt    B
    Store   A

Endloop, Load   A
    Skipcond 000 
    Jump    IncrementX

    Load    X
    Output   
    Halt
A,  DEC     0
B,  DEC     0
X,  DEC     0
One, DEC    1

Code in ARM :

MOV     R1,#128   ;divide R1 by R2
 MOV     R2,#4     ;
 MOV     R0,#0     ;initialise counter
.subtract
 SUBS    R1,R1,R2  
 ADD     R0,R0,#1  ;
 BHI     subtract  ;
Add a comment
Know the answer?
Add Answer to:
Write a subroutine code to divide two positive numbers by repeated subtraction method. For exampl...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT