How to use for loop in Assembly?Why are loops always compiled into “do…while” style (tail jump)?8086 ASM: Turbodebugger opens text file, executing normally doesn'tSorting strings in 8086 AssemblyUsing Jump and Compare in Assembly LanguageReplacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsmov ah,01h int16h, how to use it to change the direction of the snakeSnake Assembly 8086: not moving correctlySnake Game Assembly: increasing body length not workingSnake Game: how to know if it bites itselfHow do i re-write this assemly lang.program so that it can double any number passed to itC++ code for testing the Collatz conjecture faster than hand-written assembly - why?

Has the Hulk always been able to talk?

How did the Apollo guidance computer handle parity bit errors?

The origin of list data structure

Is Iron Man stronger than the Hulk?

All of my Firefox add-ons been disabled suddenly, how can I re-enable them?

no sense/need/point

Why would a military not separate its forces into different branches?

Should homeowners insurance cover the cost of the home?

Drawing an hexagonal cone in TikZ 2D

MX records from second domain to point to first domain but email is not delivered like on first domain

Why didn't this character get a funeral at the end of Avengers: Endgame?

Dihedral group D4 composition with custom labels

Which "exotic salt" can lower water's freezing point by –70 °C?

How to pass query parameters in URL in Salesforce Summer 19 Release?

about academic proof-reading, what to do in this situation?

Is disk brake effectiveness mitigated by tyres losing traction under strong braking?

What's the 2-minute timer on mobile Deutsche Bahn tickets?

Would a "Permanence" spell in 5e be overpowered?

Who filmed the Apollo 11 trans-lunar injection?

Should I simplify my writing in a foreign country?

Speed up this NIntegrate

As black, how should one respond to 4. Qe2 by white in the Russian Game, Damiano Variation?

How to remap repeating commands i.e. <number><command>?

Constitutional limitation of criminalizing behavior in US law?



How to use for loop in Assembly?


Why are loops always compiled into “do…while” style (tail jump)?8086 ASM: Turbodebugger opens text file, executing normally doesn'tSorting strings in 8086 AssemblyUsing Jump and Compare in Assembly LanguageReplacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsmov ah,01h int16h, how to use it to change the direction of the snakeSnake Assembly 8086: not moving correctlySnake Game Assembly: increasing body length not workingSnake Game: how to know if it bites itselfHow do i re-write this assemly lang.program so that it can double any number passed to itC++ code for testing the Collatz conjecture faster than hand-written assembly - why?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I was tasked to do a code that would output the equal amount of 'Text Here' depending on the user input. However, I seem to get bewildered by my cmp function.



;Get keyboard input
mov ah, 01h
int 21h

;Save to bl for later use
mov bl, al
jmp isa

isa:
mov ah, 09h
mov dx, offset text
int 21h

cmp bl, bl
jne isa
je exit


What I get with this code is only one output of 'Text' no matter what number I input.



EDIT: I tried this but now my output is infinite :(



isa:
inc bl
mov ah, 09h
mov dx, offset ulit
int 21h


cmp bl, 30h
jne isa
je exit









share|improve this question
























  • As written, this should be an infinite loop, because you never decrement BL. What is text? Is it terminated with a dollar sign as the DOS API expects?

    – Cody Gray
    Mar 23 at 4:43











  • @CodyGray: This is cmp, not test. It's checking if bl is equal to itself, like a sub same,same zeroing idiom. Based on the title, this is maybe a duplicate of my Q&A about looping (Why are loops always compiled into "do...while" style (tail jump)?), but the question body is more like how to use cmp. But IDK what they want as an exit condition, so close as unclear would be reasonable.

    – Peter Cordes
    Mar 23 at 4:48












  • Of course it is. The eyes see what they want to see. Not so sure about that duplicate marking, though, @Peter. I assume you were marking it as a canonical "how do I write a loop in asm?" question, but I don't think your answer there really shows that.

    – Cody Gray
    Mar 23 at 4:53











  • @CodyGray: yeah, you're right. It has some example loops, but all the text assumes the reader already understands the fundamentals of how loops work. I don't recall any particular tutorial Q&A about how to loop, but I'm sure there have been many answers that explain it in passing. :/

    – Peter Cordes
    Mar 23 at 4:57











  • @CodyGray Yes I'm sorry I forgot about the $ sign. 'Text' simply any is any text we would like to be looped.

    – Sifeng
    Mar 23 at 10:37

















0















I was tasked to do a code that would output the equal amount of 'Text Here' depending on the user input. However, I seem to get bewildered by my cmp function.



;Get keyboard input
mov ah, 01h
int 21h

;Save to bl for later use
mov bl, al
jmp isa

isa:
mov ah, 09h
mov dx, offset text
int 21h

cmp bl, bl
jne isa
je exit


What I get with this code is only one output of 'Text' no matter what number I input.



EDIT: I tried this but now my output is infinite :(



isa:
inc bl
mov ah, 09h
mov dx, offset ulit
int 21h


cmp bl, 30h
jne isa
je exit









share|improve this question
























  • As written, this should be an infinite loop, because you never decrement BL. What is text? Is it terminated with a dollar sign as the DOS API expects?

    – Cody Gray
    Mar 23 at 4:43











  • @CodyGray: This is cmp, not test. It's checking if bl is equal to itself, like a sub same,same zeroing idiom. Based on the title, this is maybe a duplicate of my Q&A about looping (Why are loops always compiled into "do...while" style (tail jump)?), but the question body is more like how to use cmp. But IDK what they want as an exit condition, so close as unclear would be reasonable.

    – Peter Cordes
    Mar 23 at 4:48












  • Of course it is. The eyes see what they want to see. Not so sure about that duplicate marking, though, @Peter. I assume you were marking it as a canonical "how do I write a loop in asm?" question, but I don't think your answer there really shows that.

    – Cody Gray
    Mar 23 at 4:53











  • @CodyGray: yeah, you're right. It has some example loops, but all the text assumes the reader already understands the fundamentals of how loops work. I don't recall any particular tutorial Q&A about how to loop, but I'm sure there have been many answers that explain it in passing. :/

    – Peter Cordes
    Mar 23 at 4:57











  • @CodyGray Yes I'm sorry I forgot about the $ sign. 'Text' simply any is any text we would like to be looped.

    – Sifeng
    Mar 23 at 10:37













0












0








0








I was tasked to do a code that would output the equal amount of 'Text Here' depending on the user input. However, I seem to get bewildered by my cmp function.



;Get keyboard input
mov ah, 01h
int 21h

;Save to bl for later use
mov bl, al
jmp isa

isa:
mov ah, 09h
mov dx, offset text
int 21h

cmp bl, bl
jne isa
je exit


What I get with this code is only one output of 'Text' no matter what number I input.



EDIT: I tried this but now my output is infinite :(



isa:
inc bl
mov ah, 09h
mov dx, offset ulit
int 21h


cmp bl, 30h
jne isa
je exit









share|improve this question
















I was tasked to do a code that would output the equal amount of 'Text Here' depending on the user input. However, I seem to get bewildered by my cmp function.



;Get keyboard input
mov ah, 01h
int 21h

;Save to bl for later use
mov bl, al
jmp isa

isa:
mov ah, 09h
mov dx, offset text
int 21h

cmp bl, bl
jne isa
je exit


What I get with this code is only one output of 'Text' no matter what number I input.



EDIT: I tried this but now my output is infinite :(



isa:
inc bl
mov ah, 09h
mov dx, offset ulit
int 21h


cmp bl, 30h
jne isa
je exit






assembly x86 dos






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 10:43







Sifeng

















asked Mar 23 at 3:06









SifengSifeng

11




11












  • As written, this should be an infinite loop, because you never decrement BL. What is text? Is it terminated with a dollar sign as the DOS API expects?

    – Cody Gray
    Mar 23 at 4:43











  • @CodyGray: This is cmp, not test. It's checking if bl is equal to itself, like a sub same,same zeroing idiom. Based on the title, this is maybe a duplicate of my Q&A about looping (Why are loops always compiled into "do...while" style (tail jump)?), but the question body is more like how to use cmp. But IDK what they want as an exit condition, so close as unclear would be reasonable.

    – Peter Cordes
    Mar 23 at 4:48












  • Of course it is. The eyes see what they want to see. Not so sure about that duplicate marking, though, @Peter. I assume you were marking it as a canonical "how do I write a loop in asm?" question, but I don't think your answer there really shows that.

    – Cody Gray
    Mar 23 at 4:53











  • @CodyGray: yeah, you're right. It has some example loops, but all the text assumes the reader already understands the fundamentals of how loops work. I don't recall any particular tutorial Q&A about how to loop, but I'm sure there have been many answers that explain it in passing. :/

    – Peter Cordes
    Mar 23 at 4:57











  • @CodyGray Yes I'm sorry I forgot about the $ sign. 'Text' simply any is any text we would like to be looped.

    – Sifeng
    Mar 23 at 10:37

















  • As written, this should be an infinite loop, because you never decrement BL. What is text? Is it terminated with a dollar sign as the DOS API expects?

    – Cody Gray
    Mar 23 at 4:43











  • @CodyGray: This is cmp, not test. It's checking if bl is equal to itself, like a sub same,same zeroing idiom. Based on the title, this is maybe a duplicate of my Q&A about looping (Why are loops always compiled into "do...while" style (tail jump)?), but the question body is more like how to use cmp. But IDK what they want as an exit condition, so close as unclear would be reasonable.

    – Peter Cordes
    Mar 23 at 4:48












  • Of course it is. The eyes see what they want to see. Not so sure about that duplicate marking, though, @Peter. I assume you were marking it as a canonical "how do I write a loop in asm?" question, but I don't think your answer there really shows that.

    – Cody Gray
    Mar 23 at 4:53











  • @CodyGray: yeah, you're right. It has some example loops, but all the text assumes the reader already understands the fundamentals of how loops work. I don't recall any particular tutorial Q&A about how to loop, but I'm sure there have been many answers that explain it in passing. :/

    – Peter Cordes
    Mar 23 at 4:57











  • @CodyGray Yes I'm sorry I forgot about the $ sign. 'Text' simply any is any text we would like to be looped.

    – Sifeng
    Mar 23 at 10:37
















As written, this should be an infinite loop, because you never decrement BL. What is text? Is it terminated with a dollar sign as the DOS API expects?

– Cody Gray
Mar 23 at 4:43





As written, this should be an infinite loop, because you never decrement BL. What is text? Is it terminated with a dollar sign as the DOS API expects?

– Cody Gray
Mar 23 at 4:43













@CodyGray: This is cmp, not test. It's checking if bl is equal to itself, like a sub same,same zeroing idiom. Based on the title, this is maybe a duplicate of my Q&A about looping (Why are loops always compiled into "do...while" style (tail jump)?), but the question body is more like how to use cmp. But IDK what they want as an exit condition, so close as unclear would be reasonable.

– Peter Cordes
Mar 23 at 4:48






@CodyGray: This is cmp, not test. It's checking if bl is equal to itself, like a sub same,same zeroing idiom. Based on the title, this is maybe a duplicate of my Q&A about looping (Why are loops always compiled into "do...while" style (tail jump)?), but the question body is more like how to use cmp. But IDK what they want as an exit condition, so close as unclear would be reasonable.

– Peter Cordes
Mar 23 at 4:48














Of course it is. The eyes see what they want to see. Not so sure about that duplicate marking, though, @Peter. I assume you were marking it as a canonical "how do I write a loop in asm?" question, but I don't think your answer there really shows that.

– Cody Gray
Mar 23 at 4:53





Of course it is. The eyes see what they want to see. Not so sure about that duplicate marking, though, @Peter. I assume you were marking it as a canonical "how do I write a loop in asm?" question, but I don't think your answer there really shows that.

– Cody Gray
Mar 23 at 4:53













@CodyGray: yeah, you're right. It has some example loops, but all the text assumes the reader already understands the fundamentals of how loops work. I don't recall any particular tutorial Q&A about how to loop, but I'm sure there have been many answers that explain it in passing. :/

– Peter Cordes
Mar 23 at 4:57





@CodyGray: yeah, you're right. It has some example loops, but all the text assumes the reader already understands the fundamentals of how loops work. I don't recall any particular tutorial Q&A about how to loop, but I'm sure there have been many answers that explain it in passing. :/

– Peter Cordes
Mar 23 at 4:57













@CodyGray Yes I'm sorry I forgot about the $ sign. 'Text' simply any is any text we would like to be looped.

– Sifeng
Mar 23 at 10:37





@CodyGray Yes I'm sorry I forgot about the $ sign. 'Text' simply any is any text we would like to be looped.

– Sifeng
Mar 23 at 10:37












1 Answer
1






active

oldest

votes


















0














First of all, make sure that you initialize the BX register to zero before you start your loop:



...
xor bx,bx
isa:
...


To avoid the DOS interrupt to overwrite the contents of your (used) BX register, secure it on the stack (not sure about the calling conventions of DOS interrupts, was too long ago for me):



...
push bx
int 21h
pop bx





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%2f55310228%2fhow-to-use-for-loop-in-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














    First of all, make sure that you initialize the BX register to zero before you start your loop:



    ...
    xor bx,bx
    isa:
    ...


    To avoid the DOS interrupt to overwrite the contents of your (used) BX register, secure it on the stack (not sure about the calling conventions of DOS interrupts, was too long ago for me):



    ...
    push bx
    int 21h
    pop bx





    share|improve this answer



























      0














      First of all, make sure that you initialize the BX register to zero before you start your loop:



      ...
      xor bx,bx
      isa:
      ...


      To avoid the DOS interrupt to overwrite the contents of your (used) BX register, secure it on the stack (not sure about the calling conventions of DOS interrupts, was too long ago for me):



      ...
      push bx
      int 21h
      pop bx





      share|improve this answer

























        0












        0








        0







        First of all, make sure that you initialize the BX register to zero before you start your loop:



        ...
        xor bx,bx
        isa:
        ...


        To avoid the DOS interrupt to overwrite the contents of your (used) BX register, secure it on the stack (not sure about the calling conventions of DOS interrupts, was too long ago for me):



        ...
        push bx
        int 21h
        pop bx





        share|improve this answer













        First of all, make sure that you initialize the BX register to zero before you start your loop:



        ...
        xor bx,bx
        isa:
        ...


        To avoid the DOS interrupt to overwrite the contents of your (used) BX register, secure it on the stack (not sure about the calling conventions of DOS interrupts, was too long ago for me):



        ...
        push bx
        int 21h
        pop bx






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 13:08









        MartinMartin

        862




        862





























            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%2f55310228%2fhow-to-use-for-loop-in-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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript