6

I'm getting stair-step output like this enter image description here

My program works correctly, except that when I print a new line, and then print something in the current line, it shows on the next line but with some space before it.


The program is this: (print a table of multiple numbers from 0 to 9):

data_seg segment
    I DB 0D
    J DB 0D
    R DB ?
    DIVER DB 10D
    data_seg ends

stack_seg segment
    stack_seg ends

code_seg segment
    MAIN proc far
        assume cs:code_seg, ds:data_seg, ss:stack_seg
        MOV AX,data_seg
        MOV DS,AX

        FOR1:
            MOV J,0D
            FOR2:
            MOV AX,0H
            MOV AL,I
            MUL J
            DIV DIVER 
            MOV R,AH
            ADD AL,48D
            MOV AH,0EH
            INT 10H
            MOV AL,R
            ADD AX,48D
            MOV AH,0EH
            INT 10H

            MOV AX,32D
            MOV AH,0EH
            INT 10H
            INC J 
            MOV AX,0
            MOV AL,J
            SUB AX,10D
            JNZ FOR2
         INC I
         MOV AX,10D
         MOV AH,0EH
         INT 10H
         MOV AX,0
         MOV AL,I
         SUB AX,10D
         JNZ FOR1

        MOV AX,4CH
        INT 21H
        MAIN endp
    code_seg ends
end MAIN
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Moein Hosseini
  • 4,309
  • 15
  • 68
  • 106
  • @jww: this is not `[windows]` code, it's DOS (for the `int 21h`), and using `int 10h` BIOS calls otherwise for some reason. – Peter Cordes Mar 13 '19 at 06:28
  • @Peter - No Microsoft tag; used Windows tag to indicate the platform. – jww Mar 13 '19 at 06:44
  • @jww: The `[dos]` tag is the appropriate one here. See my edit. Nothing about this code has anything to do with Windows, other than the fact that some 32-bit versions of Windows come with a DOS virtual machine. That's why there's a separate tag for DOS. – Peter Cordes Mar 13 '19 at 06:48
  • @Peter - The dollar sign terminator tells me it is Microsoft technologies. MASM used it for string termination. Doubtful it is DOS in 2011; 15 years too late. – jww Mar 13 '19 at 06:50
  • @jww: not everything Microsoft has made is Windows. DOS existed first, and is separate. And `$` terminators started with CP/M, copied by DOS but *not* Windows. (Windows uses 0-terminated C strings in low-level WinAPI functions like for filenames). Also, the *question* doesn't use any DOS string functions, that's only in one of the answers, so it might not even be useful if the DOS exit call is just there to test bootloader code under DOS. Anyway, if there was no DOS tag, your edit might have been justified (but creating a DOS tag would have been better). But it's clearly wrong. – Peter Cordes Mar 13 '19 at 06:54
  • @Peter - Lol... DOS is dead. But keep believing folks are using it if it makes you happy. – jww Mar 13 '19 at 06:55
  • 1
    @jww: DOS is still used to test newly-developed motherboards, and for some insane reason some schools (many in India) teach assembly language with 16-bit DOS. Many of them with emu8086. (Somewhat like MARS/SPIM GUI editor+debugger+simulator, but for 8086, including DOS). I *wish* DOS was dead, but it's not. It's embedded OS that gets out of the way, I can see the use-case. https://www.freedos.org/ is still maintained, for use in embedded stuff apparently. I have zero interest in DOS, but you clearly haven't spent much time looking in the `[x86]` tag if you think DOS is dead. – Peter Cordes Mar 13 '19 at 07:02
  • @jww: Literally all the DOS questions I've seen on SO are from beginners who are stuck with it for school, or for some reason picked it for self-teaching (although self-taught are usually "writing their own OS" as a legacy BIOS MBR bootloader, so x86-16 but not DOS, just BIOS calls). But there's a significant volume of such questions. The people who actually use DOS for testing engineering-sample mobos or other use-cases don't need to ask yet another duplicate about reading / printing multi-digit numbers or how `div` works on SO. – Peter Cordes Mar 13 '19 at 07:05
  • 1
    @jww: more importantly, you *can't* run this code on a modern 64-bit Windows system without an emulator like DOSBOX or BOCHs. – Peter Cordes Mar 13 '19 at 07:07

5 Answers5

9

if your using emu80x86 this code should do it

mov dx,13
  mov ah,2
  int 21h  
  mov dx,10
  mov ah,2
  int 21h
MRNakh
  • 157
  • 1
  • 5
  • 14
9

You need to print new line and carriage return.

Anthony Blake
  • 5,328
  • 2
  • 25
  • 24
5

This would print a new line:

1) Add in the data segment:

linefeed db 13, 10, "$"

2) And then use this anywhere you need a new line:

; new line
mov ah, 09
mov dx, offset linefeed
int 21h
bhaskarc
  • 9,269
  • 10
  • 65
  • 86
3

AS anthony said, Based on your assembler, you need to do a carriage return and line feed to go to next line and place cursor at the beggining of the line. For MASM you can use Call crlf or print values 0dh and 0ah respectively.

-3

try to put lanes for line return

mov ax, 4c00h ; return to ms-dos
int 21h
Yappie
  • 399
  • 2
  • 8