flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > Print.com - Similar to CMD echo command

Author
Thread Post new topic Reply to topic
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 21 Feb 2010, 17:55
Can someone help me? I made this program to echo what the user places in it's command-line. When it encounters special parameters such as '\n' it should place the following part of the string on a newline. The problem is, it should print the text "MeshNix" in color and I can find a solution to do so. Can you help assist me in correcting the errors in the code.
Code:
;Syntax: Print Hello\nWorld!
;        Switches: -\n Newline
;                  -\p Paragraph   
;                  -\i Indent
;                  -\w Watermark ("MeshNix")
;                  -\\ Backslash
;The problem here is the Indent switch and the Watermark switch
;They aren't working.

org 100h

start:
   ;Get command-line
        mov ch,01h
        mov di,81h
        mov al,' '
        repe scasb
        lea dx,[di-1]
        dec di
        mov al,13
        repne scasb
        mov byte [di-1],0

        mov si,dx      ;place string on stack
        jmp GetChar    ;skip printing

 PrintChar:
        mov ah,0eh
        int 10h     ;print character
 GetChar:
        mov al,[si]     ;extract byte from si
        inc si     ;step-up on stack
  ;find newline character
        cmp al,'\'     ;check for newline char
        je .token_backslash
        cmp al,';'     ;check for eol char
        je .finish
        or al,al     
        jz .finish

        jmp PrintChar  ;print character

.finish:
       ret             ;terminate program

.token_backslash:
       mov al,[si]
       inc si
    check.newline:
       cmp al,'n'
       jne check.paragraph
       mov dx, newline
       mov ah,9
       int 21h
       jmp GetChar

    check.paragraph:
       cmp al,'p'
       jne check.indentation
       ;skip make two newline to create paragraph
       mov dx, newline
       mov ah,9
       int 21h
       mov dx, newline
       mov ah,9
       int 21h
       jmp GetChar
    check.indentation:
       cmp al,'i'
       jne check.watermark
       mov dx, indent
       mov ah,9
       int 21h
       jmp GetChar
    check.watermark:
       cmp al,'w'
       jne check.backslash
       mov si,watermark.pt1
       jmp GetChar.Mesh
       ;print the text "Mesh" in white
       PrintChar.Mesh:
       mov ah,0Eh
       mov bh,00h
       mov cx,1
       int 10h
       GetChar.Mesh:
       mov al,[si]
       inc si
       or al,al
       jz GetChar.Nix
       jmp PrintChar.Mesh

       ;print the text "Nix" in blue
       PrintChar.Nix:
       mov ah,0Eh
       mov cx,1
       mov bh,00h
       int 10h
       jmp GetChar.Nix
       InputString:
       inc si
       mov si,watermark.pt2
       GetChar.Nix:
       mov al,[si]
       inc si
       or al,al
       jz GetChar
       jmp PrintChar.Nix

    check.backslash:
       cmp al,'\'
       jne GetChar
       mov dx,backslash
       mov ah,9
       int 21h
       jmp GetChar


;data
newline       db 13,10,24h,0
indent        db '      ',24h,0
watermark.pt1 db 'Mesh',0
watermark.pt2 db 'Nix',0
backslash     db '\',24h,0           
[/code]

_________________
meshnix
Post 21 Feb 2010, 17:55
View user's profile Send private message Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 21 Feb 2010, 17:56
Sorry for the Loose comments
Post 21 Feb 2010, 17:56
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 21 Feb 2010, 18:26
MeshNix,

int10/0E allows to specify foreground color only in graphic modes. In text modes attribute byte retains it's value. Use int10/09 or /13.
Post 21 Feb 2010, 18:26
View user's profile Send private message Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 21 Feb 2010, 20:02
Thanks. But how do I use these interrupts.
I used int 10h to use color in the text, but the problem is, it cleared the screen and wrote the character at the start of the screen.

Previously, I saw this code, and it involved, using displaying color text. I realized each time the program printed a character to the screen, it adjusted the cursor position, in order to do so.

_________________
meshnix
Post 21 Feb 2010, 20:02
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.