How to make a 8086 clear screen then move the cursor to a newline to print out the next function

Viewed 200

Because i tried mine it does not work it will end it immediately

  mov ah,00
  mov al,02
  int 10h
  int 21h
  
  mov ah,02h     
  mov bh,00
  mov dx, 0000h
  int 10h 
  ret     
1 Answers

Analyzing what you wrote

mov ah,00     \ 
mov al,02     | These select the 80x25 video mode
int 10h       /
int 21h       <<<<<< ERROR 1
mov ah,02h    \
mov bh,00     | These place the cursor in the upperleft corner
mov dx, 0000h |
int 10h       /
ret           <<<<<< ERROR 2

In ERROR 1 you have a stray call to the DOS api. Because you didn't specify the function number that you want in the AH register, that register still held the number 00h from the code above. Now, DOS function 00h happens to be a function that terminates the program. The rest of your code doesn't even get a chance to run...

In ERROR 2 you're using the ret instruction to end the program. That works in a .COM program as long as the stack is untampered with. However to obtain such a program you need to write an ORG 256 directive on the first line.


What do do

You can clear the screen by setting the video mode (like you did), but you should realize that the cursor will already have been placed in the upperleft corner of the screen, so it will be useless to set it there again.

If you need to move the cursor to the beginning of the same line, you should output the byte 13 for carriage return.
If you need to move the cursor down one line but stay in the same column, you should output the byte 10 for linefeed.
In general, to execute a newline, you output both bytes in succession.

If you want to output some text, it would be easiest to use the DOS.PrintString function 09h.

ORG  256

mov  ax, 0003h       ; BIOS.SetVideoMode 80x25
int  10h

mov  dx, offset Msg
mov  ah, 09h         ; DOS.PrintString
int  21h

mov  ah, 00h         ; BIOS.WaitKeyboardKey
int  16h             ; -> AX

ret                  ; Terminate .COM program

Msg  db  10, 'Welcome', 13, 10, 10, 'sherley', 13, 10

The BIOS.WaitKeyboardKey call is there to pause the program so you can see the output before it disappears again.

Related