Search code examples
loopsassemblyx86masmirvine32

Is there a way to display a loop all on one line in assembly?


So I am working on trying to get a loop to display something five times without going to a new line. Specifically, I want to display the word "Loop" 5 times on one line, "LoopLoopLoopLoopLoop." I am able to display them on separate lines easy enough, it seems like it automatically goes to a new line all by itself. I am quite new to assembly language so if anyone could explain what is going on here it would be a huge help.
Here is my code:

INCLUDE Irvine32.inc
.data
myMessageOne BYTE "Loop",0dh,0ah,0
.code
main PROC
    call Clrscr
    mov edx, OFFSET myMessageOne
    mov ecx, 5
myloopOne:
    call WriteString
    loop myloopOne
    call DumpRegs
    exit

It prints out this:

Loop
Loop
Loop
Loop
Loop

But I need:

LoopLoopLoopLoopLoop

I've tried using jmp in an attempt to move it back up to the line, but it doesn't work. I don't know too many other commands and all the things I've looked up to try and find a solution just seem to be people looking for help with new line, the exact opposite of what I need help with. Any tips and help are very much appreciated as I'd like to get a better understanding of what I need to do.

Also, I am using Microsoft Visual C++ 2010 Express. It is my understanding that what program you are using matters more in assembly.


Solution

  • as long as the CR/LF is part of your string, it's displayed each time. remove it, and make it another message:

    INCLUDE Irvine32.inc
    .data
    myMessageOne BYTE "Loop",0
    str_crlf     BYTE 0dh,0ah,0
    
    .code
    main PROC
        call Clrscr
    
    ; write 5 "loop"s 
        mov edx, OFFSET myMessageOne     
        mov ecx, 5
    myloopOne:
        call WriteString
        loop myloopOne
    
    ; and then the newline
        mov edx, OFFSET str_crlf
        call WriteString
    
        call DumpRegs
        exit