assembly - x86 Strange printing after console has been scrolled -
i have following function:
printrows proc mov cx, 25 printrowsloop: mov si, 0 printsinglerowloop: mov ah, 3 ;save current cursor position @ dx (dh:dl) int 10h push dx ;keep position later mov ah, 2 mov dl, '&' int 21h ; print '&' char in current curser position pop dx ; restore dx add dl, 5 ; increase column of const number (so square) mov ah, 2 int 10h inc si cmp si, 3 ; print 3 '&' in each row jne printsinglerowloop mov dl, 13 ; result of these 3 groups of commands should 2 new lines mov ah, 2 int 21h mov dl, 10 ;mov ah, 2 ; ah alredy 2 int 21h ;mov dl, 10 ; dl 10 ;mov ah,2 ; ah 2 int 21h loop printrowsloop ; print (cx) lines ret printrows endp
the output of should seen in this screenshot - , output of (at least in begginig)
but, after "good" output filled console (when needed "scroll") doesn't longer print spaces between each '&', instead prints each of them in new line as can seen here.
what might cause such strange behaviour? doing wrong? how should fix this?
i using emu8086.
you should print carriage return (13 ascii code) last.
i have included fifoernik's tips in answer.
printrows proc mov cx, 25 printrowsloop: mov si, 0 printsinglerowloop: push cx mov bh, 0 mov ah, 3 ;save current cursor position @ dx (dh:dl) int 10h pop cx push dx ;keep position later mov ah, 2 mov dl, '&' int 21h ; print '&' char in current curser position pop dx ; restore dx mov bh, 0 add dl, 5 ; increase column of const number (so square) mov ah, 2 int 10h inc si cmp si, 3 ; print 3 '&' in each row jne printsinglerowloop mov dl, 10 ;mov ah, 2 ; ah alredy 2 int 21h ;mov dl, 10 ; dl 10 ;mov ah,2 ; ah 2 int 21h mov dl, 13 ; <<<<<<<<<<<<<<<<<<<<< print carriage return last! ;mov ah, 2 ; ah 2 int 21h loop printrowsloop ; print (cx) lines ret printrows endp
no need space character:)