Reputation: 13
I am doing a program on dosbox assembly where i print 0 to 9 diagonally. Here is my current code
code segment
assume cs:code, ds:code
org 100h
start:
mov ah, 02h
mov dl, 30h
mov ch, 30h
int 21h
again:
inc dl ;output next number
mov bl, dl
mov dl, 0ah ;new line
int 21h
mov dl, 20h ;space
int 21h
mov dl, bl
int 21h
inc ch ;increment counter
cmp ch, 39h ;if counter is at 9 end program
je terminate
loop again
terminate:
mov ax, 4c00h
int 21h
code ends
end start
The problem is when i add a new line, the cursor goes back to the beginning of the next line, so printing diagonally is impossible. Is there a way that I can print a new line, but the cursor stays on the current position? I've read somewhere that 'Line Feed' can solve my problem, but it has been changed to 'New Line', where after adding a new line, the cursor automatically goes back to the starting position ala automatic 'Carriage Return'
EDIT: Thanks everyone for checking out this question. We aren't allowed to use those other functions aside from loop, jmp, and cmp. My friend figured out how to do it, but I still don't understand maybe 2/3 of their code, mainly on the again2 and jump loops. Code: https://pastebin.com/Vji29VL3.
Upvotes: 1
Views: 1713
Reputation: 1243
An alternative to BIOS functions would be to write directly to video.
mov al, 30H
mov cx, B800H
mov es, cx
xor di, di ; Change if you don't want to start at top/left.
mov cx, 161 ; STOSB has already incremented by one.
Loop:
stosb
add di, cx
inc al
cmp al, 9
jbe Loop
Of course this makes a few assumption, particularly that you're writing to page 0 and attribute is set to something that will actually display. If you prefer you could also establish an attribute in AH, then use STOSW and only add 160 to DI each time.
Upvotes: 1