tags:

views:

299

answers:

3

I have an ASM script that displays date(day, month, year) and time(hours, minutes, seconds).

This prints the current datetime on the DOS-box. Thing is, it's static. What I want to do is make it dynamic, meaning I have to write the new value in the exact place where the current value is standing on the screen. How do you do this in ASM?

I don't have any clue at all and google hasn't been my friend for this.

A: 

If your DOS-box is COMMAND.COM, or CMD.EXE prior to Windows 2000 (newer CMD.EXE do not offer ANSI support), then it will support ANSI escape sequences. You can use various cursor commands to position the cursor at the beginning of your clock before displaying the new time.

Sparr
+1  A: 

Use the ASM code to position your cursor before printing your string. For example:

        MOV     DX,1629H                ; (LINE 16H, COL 29H)
        MOV     AH,2                    ; Move cursor to DH,DL
        INT     10H
        ; now print your string
BoltBait
Don't forget to load the page number (almost always 0) into BH.
P Daddy
A: 

This isn't really a language-specific issue, but more of a platform-specific one. You said you're running on a DOS box, so you could use one of the following:

  1. If you're using a DOS print routine (such as INT 21h with AH=9), you can print a carriage return character (ASCII 13) without a subsequent newline character (ASCII 10) to return the cursor to the beginning of the current line. Similarly, if this is actually a console-based Windows app, and you're using WriteConsole, you should achieve the same effect.
  2. If you're truly using DOS, you can use the BIOS to update the current cursor position with INT 10h, AH=2.
  3. As mentioned by Sparr, you can send "ANSI" escape sequences (if ansi.sys is loaded) to control the cursor, as well as other things, such as color. These escape sequences would be printed (e.g., ala INT 21h, AH=9), just like your text.


If you're going to be doing much assembly programming in DOS, I'd keep a bookmark to one of several interrupt references.

P Daddy