Results 1 to 7 of 7

Thread: 8086 Assembly question

  1. #1
    Senior Member
    Join Date
    Feb 2002
    Posts
    133

    8086 Assembly question

    I'm writing a program in 8086 assembly to be used in dos and I want it to print out certain messages in color. I know how to print messages to screen using int 21H (with 9 in ah), and I want the text to be printed in the same way as using int 21H but I want it in color. I know int 10H is involved but I have no idea what must be in the other registers for it to work. Does anybody know???
    Any help will be greatly appreciated.

    Regards,
    Garathjax
    If you don\'t learn the rules nobody can accuse of cheating.

  2. #2
    Senior Member
    Join Date
    Jul 2002
    Posts
    339
    Tough job isn't it? I see you've got greenies just for asking...

    I need to dig my memory back in 1992 when I WAS a 8086 assembly coder... OK. Int 21H with AH=9 is only used to print messages to screen in console mode. Use Int 10H with AH=9, AL=ASCII code of the character you want to print and BL=attribute. Use Int 10H with AH=2, DH=row and DL=column to position the cursor.

    Notice that Int 10H only print a single char, not a string of char, so you need to call it with AL=ASCII of the first char, then with AL=ASCII of the second char, and so on. You can use # of characters, or have a terminating character like null, to end the repetition. You know how to create a loop block in assembly, don't you? I was going to give you an example, but I figured out that it'd be more than 20 lines... too lazy

    For reference, as always, search "int 10h" at google. I wonder though, why would you need to code in assembly these days? Second, why would you need to print message to character mode screen in this GUI era? Anyway, good luck!

    EDIT: While we're in this topic, there is an alternative way to do it. Assuming you will be running the program in DOS box with CGA/VGA monitor, you can write directly the character (with attribute) to the screen memory's base segment (CGA = B800h, VGA = B000h). Assuming you will be using a 80x24 character screen mode, offset 0 is used to specify the ASCII code of the character in position x=1, y=1, and offset 1 is used for its attribute. Offset 2 is for character in x=2, y=1, and offset 3 is its attribute, and so on. This method is faster than using int 10h, since you directly write to memory so less overhead. But, be careful NOT to write to the wrong memory address, and do NOT use this method in a Windows box, or you may crash your system!

    Peace always,
    <jdenny>
    Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
    I\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds


  3. #3
    AO Curmudgeon rcgreen's Avatar
    Join Date
    Nov 2001
    Posts
    2,716
    Code:
    n bluescrn.com
    e 147 "redhead"
    e 150 "THIS PROGRAM HAS" 20 20 20 20
    e 164 "COMMITTED A HEINOUS" 20
    e 178 "CRIME AND WILL BE" 20 20 20
    e 18c "EXTERMINATED" 20 20 20 20 20 20 20 20
    
    a 100
    mov ax,0003           ;set video mode #3 (also clears screen)
    int 10                ;BIOS video services
    mov ax,09db           ;write character # DB hex
    mov bx,0001           ;display page #0,char attribute #01 (blue)
    mov cx,07d0           ;# of repetitions of char to fill screen
    int 10                ;BIOS video services
    mov bp,0150           ;offset location of first string
    mov ax,1301           ;write string service
    mov bx,001f           ;display page #0,char attribute #17 (white)
    mov cx,0014           ;length of string
    mov dx,091c           ;cursor location for first string
    int 10                ;BIOS video services (writes first string)
    mov bp,0164           ;offset of second string
    mov dx,0a1c           ;cursor location for 2nd string
    int 10                ;BIOS video services (writes 2nd string)
    mov bp,0178           ;offset of third string
    mov dx,0b1c           ;cursor location for third string
    int 10                ;BIOS video services (writes third string)
    mov bp,018c           ;offset of fourth string
    mov dx,0c1c           ;cursor location for 4th string
    int 10                ;BIOS video services (writes 4th string)
    mov ah,02             ;move cursor
    mov dx,0000           ;to upper left of screen
    int 10                ;BIOS video services
    mov ax,0c08           ;clear keyboard buffer and wait for any key
    int 21                ;DOS services
    int 20                ;terminate program (and exit to DOS)
    
    r cx
    a0
    w
    q
    with int 10h, you put the service you want into AH, and other parameters in AL
    like set video mode put 00 in AH, and the mode number in AL.

    To put a character on screen, it is 09 in AH, the character in AL,
    display page(of video memory) in BH, and character attribute (color)
    in BL, and number of characters in CX

    If you want to do a string, put its address into BP,
    1300 or 1301 into AX (slightly different services, but either works)
    again BH and BL are display page and attribute,
    length of string goes in CX, and cursor position in DX.

    The above code should make a bogus "blue screen of death"
    it is in the form of a debug script. compile it by
    making it into a file and redirecting it to DEBUG thus:
    DEBUG<filename (enter)
    I came in to the world with nothing. I still have most of it.

  4. #4
    Senior Member
    Join Date
    Feb 2002
    Posts
    133
    Thanks for the info, it was a great help.
    The way I printed the text in color (if anybody is interested) was to move 1301H in to AX, 0009H into BX (prints the text in a bright blue color), move the size of the string to be printed (in bytes into CX), move the initial cursor position into DX and point to the string with BP. One important point (which took me a while to figure out) was to have the message has to be in the extra segment register (ES), it wouldn't work if the message was anywhere else (such as the data segment).

    I still have one more question however. Is there anyway I can find the position of the cursor on the dos screen (before the program is called) so I know what value to put into DX. Currently I am initially putting 0000H into DX but that is causing information to be overwritten that I want to keep on the screen. I persume int 10H can find this aswell but I don't know how (when I try googling int10H I get tons of info that would take forever to wade though).
    Again thanks in advance for any info.

    Regards,
    Garathjax

    P.s. the reason I am coding in assembly is cause I want to make a (very) small game using ascii characters. I've got it working in black and white but I want to add a bit of color.
    If you don\'t learn the rules nobody can accuse of cheating.

  5. #5
    AO Curmudgeon rcgreen's Avatar
    Join Date
    Nov 2001
    Posts
    2,716
    Code:
    MOV     AH,02                 ;move cursor
    MOV     DX,0115               ;top line column 15 (hex)
    INT     10                    ;BIOS video services
    The service for moving the cursor is 02h in AH and screen coordinates in DX.
    DH is the vertical (line), and DL is the horiz. (column)

    see larger example here
    I came in to the world with nothing. I still have most of it.

  6. #6
    Senior Member
    Join Date
    Feb 2002
    Posts
    133
    What I wanted to do is find the co-ordinates of the cursor before the cursor was called. To do that what you do is (I figured it out by alot of experimenting):
    Code:
    mov ah, 3
    int 10H
    and after this DX contains the co-ordinates of the cursor.

    When 2 is in AH you can set the position of the cursor.
    If you don\'t learn the rules nobody can accuse of cheating.

  7. #7
    AO Curmudgeon rcgreen's Avatar
    Join Date
    Nov 2001
    Posts
    2,716
    Here's a nice list of the int10h services:

    http://www.clipx.net/ng/bios/ngd4d7.php
    I came in to the world with nothing. I still have most of it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •