im trying this code but i was not able perfectly print diagonally in alphabet order.. can you help me to this code? program output screenshot
.model small
.stack
.code
start:
mov cx,26
mov bh,00
mov ah,02h
mov dl,41h
mov dh,02h
again:
int 10h
int 21h
inc dl
inc dh
loop again
mov ah,4ch
int 21h
end start
All the problems with this code stem from the fact that both the BIOS function 02h (SetCursor) and the DOS function 02h (WriteCharacter) use the DL
register as a parameter. Unluckily for you the meaning is different in this cases. Several solutions exist. Using the free register BL
to keep a separate character code was suggested by Ped7g.
A simple solution that I present is not using the DOS output function at all, and writing to the display with BIOS function 0Eh (TeletypeCharacter). This function does not rely on DL
as a parameter. It rather uses the AL
register.
.model small
.stack
.code
start:
mov al, "A" <<<First character
mov bh, 0 <<<Display page 0
mov cx, 25 <<<Iteration count
mov dl, 0 <<<Start at column 0
mov dh, 0 <<<Start at row 0
again:
mov ah, 02h <<<BIOS function SetCursor
int 10h
mov ah, 0Eh <<<BIOS function TeleType
int 10h
inc dl <<<Next column
inc dh <<<Next row
inc al <<<Next character
loop again
mov ah, 4Ch
int 21h
end start
When working on the standard textscreen there are 80 columns and 25 rows. You should not position the cursor off-screen! The most iterations your program should perform therefore is 25.