How can I multiply and divide by odd constants in arm Assembly?












0















I don’t know how to multiply or divide by an odd constant. In the image (Link to image ), I know how to solve the first two problem (with the left and the right shift) but not the last two.



How can I do the exercise number 3 and number 4?
I resolved the first like this:



ADD r1, r2, lsl #3


So I’d Like something like that for the last two.










share|improve this question




















  • 4





    You know that x*5=x*4+x right? Also (3/4)*x=(3*x)/4=(2*x+x)/4. Any problems doing these? PS: these will take more than a single instruction.

    – Jester
    Nov 23 '18 at 12:53








  • 2





    Welcome to StackOverflow! Please be aware that this isn't a homework service - asking a good SO question is about documenting your attempts to solve a problem and then asking for help with something specific that you don't understand, rather than asking for someone to write code for you.

    – cooperised
    Nov 23 '18 at 13:18











  • You're only dividing by even constants, powers of 2 in fact, so it's just shifts. Is (3/4) * x really supposed to be evaluated with integer math? If so, the answer is zero because (3/4) truncates to 0. Otherwise, are you supposed to be keeping some fraction bits in the other cases where you divide by 4?

    – Peter Cordes
    Nov 23 '18 at 18:12











  • I don’t know I only have to put the value from 3/4 * r2 in r1

    – Noemi Pecorari
    Nov 25 '18 at 19:39
















0















I don’t know how to multiply or divide by an odd constant. In the image (Link to image ), I know how to solve the first two problem (with the left and the right shift) but not the last two.



How can I do the exercise number 3 and number 4?
I resolved the first like this:



ADD r1, r2, lsl #3


So I’d Like something like that for the last two.










share|improve this question




















  • 4





    You know that x*5=x*4+x right? Also (3/4)*x=(3*x)/4=(2*x+x)/4. Any problems doing these? PS: these will take more than a single instruction.

    – Jester
    Nov 23 '18 at 12:53








  • 2





    Welcome to StackOverflow! Please be aware that this isn't a homework service - asking a good SO question is about documenting your attempts to solve a problem and then asking for help with something specific that you don't understand, rather than asking for someone to write code for you.

    – cooperised
    Nov 23 '18 at 13:18











  • You're only dividing by even constants, powers of 2 in fact, so it's just shifts. Is (3/4) * x really supposed to be evaluated with integer math? If so, the answer is zero because (3/4) truncates to 0. Otherwise, are you supposed to be keeping some fraction bits in the other cases where you divide by 4?

    – Peter Cordes
    Nov 23 '18 at 18:12











  • I don’t know I only have to put the value from 3/4 * r2 in r1

    – Noemi Pecorari
    Nov 25 '18 at 19:39














0












0








0








I don’t know how to multiply or divide by an odd constant. In the image (Link to image ), I know how to solve the first two problem (with the left and the right shift) but not the last two.



How can I do the exercise number 3 and number 4?
I resolved the first like this:



ADD r1, r2, lsl #3


So I’d Like something like that for the last two.










share|improve this question
















I don’t know how to multiply or divide by an odd constant. In the image (Link to image ), I know how to solve the first two problem (with the left and the right shift) but not the last two.



How can I do the exercise number 3 and number 4?
I resolved the first like this:



ADD r1, r2, lsl #3


So I’d Like something like that for the last two.







assembly arm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 16:02









Stoogy

735724




735724










asked Nov 23 '18 at 12:47









Noemi PecorariNoemi Pecorari

82




82








  • 4





    You know that x*5=x*4+x right? Also (3/4)*x=(3*x)/4=(2*x+x)/4. Any problems doing these? PS: these will take more than a single instruction.

    – Jester
    Nov 23 '18 at 12:53








  • 2





    Welcome to StackOverflow! Please be aware that this isn't a homework service - asking a good SO question is about documenting your attempts to solve a problem and then asking for help with something specific that you don't understand, rather than asking for someone to write code for you.

    – cooperised
    Nov 23 '18 at 13:18











  • You're only dividing by even constants, powers of 2 in fact, so it's just shifts. Is (3/4) * x really supposed to be evaluated with integer math? If so, the answer is zero because (3/4) truncates to 0. Otherwise, are you supposed to be keeping some fraction bits in the other cases where you divide by 4?

    – Peter Cordes
    Nov 23 '18 at 18:12











  • I don’t know I only have to put the value from 3/4 * r2 in r1

    – Noemi Pecorari
    Nov 25 '18 at 19:39














  • 4





    You know that x*5=x*4+x right? Also (3/4)*x=(3*x)/4=(2*x+x)/4. Any problems doing these? PS: these will take more than a single instruction.

    – Jester
    Nov 23 '18 at 12:53








  • 2





    Welcome to StackOverflow! Please be aware that this isn't a homework service - asking a good SO question is about documenting your attempts to solve a problem and then asking for help with something specific that you don't understand, rather than asking for someone to write code for you.

    – cooperised
    Nov 23 '18 at 13:18











  • You're only dividing by even constants, powers of 2 in fact, so it's just shifts. Is (3/4) * x really supposed to be evaluated with integer math? If so, the answer is zero because (3/4) truncates to 0. Otherwise, are you supposed to be keeping some fraction bits in the other cases where you divide by 4?

    – Peter Cordes
    Nov 23 '18 at 18:12











  • I don’t know I only have to put the value from 3/4 * r2 in r1

    – Noemi Pecorari
    Nov 25 '18 at 19:39








4




4





You know that x*5=x*4+x right? Also (3/4)*x=(3*x)/4=(2*x+x)/4. Any problems doing these? PS: these will take more than a single instruction.

– Jester
Nov 23 '18 at 12:53







You know that x*5=x*4+x right? Also (3/4)*x=(3*x)/4=(2*x+x)/4. Any problems doing these? PS: these will take more than a single instruction.

– Jester
Nov 23 '18 at 12:53






2




2





Welcome to StackOverflow! Please be aware that this isn't a homework service - asking a good SO question is about documenting your attempts to solve a problem and then asking for help with something specific that you don't understand, rather than asking for someone to write code for you.

– cooperised
Nov 23 '18 at 13:18





Welcome to StackOverflow! Please be aware that this isn't a homework service - asking a good SO question is about documenting your attempts to solve a problem and then asking for help with something specific that you don't understand, rather than asking for someone to write code for you.

– cooperised
Nov 23 '18 at 13:18













You're only dividing by even constants, powers of 2 in fact, so it's just shifts. Is (3/4) * x really supposed to be evaluated with integer math? If so, the answer is zero because (3/4) truncates to 0. Otherwise, are you supposed to be keeping some fraction bits in the other cases where you divide by 4?

– Peter Cordes
Nov 23 '18 at 18:12





You're only dividing by even constants, powers of 2 in fact, so it's just shifts. Is (3/4) * x really supposed to be evaluated with integer math? If so, the answer is zero because (3/4) truncates to 0. Otherwise, are you supposed to be keeping some fraction bits in the other cases where you divide by 4?

– Peter Cordes
Nov 23 '18 at 18:12













I don’t know I only have to put the value from 3/4 * r2 in r1

– Noemi Pecorari
Nov 25 '18 at 19:39





I don’t know I only have to put the value from 3/4 * r2 in r1

– Noemi Pecorari
Nov 25 '18 at 19:39












1 Answer
1






active

oldest

votes


















0














1) MUL r1, r2, lsl #2 → ADD r1, r1, r2
2) MUL r1, r2, lsl #1 → ADD r1, r1, r2 →  MUL r1, r1, lsr #2






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447007%2fhow-can-i-multiply-and-divide-by-odd-constants-in-arm-assembly%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    1) MUL r1, r2, lsl #2 → ADD r1, r1, r2
    2) MUL r1, r2, lsl #1 → ADD r1, r1, r2 →  MUL r1, r1, lsr #2






    share|improve this answer




























      0














      1) MUL r1, r2, lsl #2 → ADD r1, r1, r2
      2) MUL r1, r2, lsl #1 → ADD r1, r1, r2 →  MUL r1, r1, lsr #2






      share|improve this answer


























        0












        0








        0







        1) MUL r1, r2, lsl #2 → ADD r1, r1, r2
        2) MUL r1, r2, lsl #1 → ADD r1, r1, r2 →  MUL r1, r1, lsr #2






        share|improve this answer













        1) MUL r1, r2, lsl #2 → ADD r1, r1, r2
        2) MUL r1, r2, lsl #1 → ADD r1, r1, r2 →  MUL r1, r1, lsr #2







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 19:47









        Andrea CulotAndrea Culot

        4918




        4918
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447007%2fhow-can-i-multiply-and-divide-by-odd-constants-in-arm-assembly%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'