1

So I've tried to code and I do not know how to change the output color. I'm new to assembly language. I want decimal blue, hex green and octal as red. Explanation with updated code is deeply appreciated. I am still new to assembly language and I would want some pointers how to learn well or will it fall off soon in the future.

org 100h

.DATA

DECIMAL DB 'Enter Decimal :$'
BINARY DB 0DH, 0AH, 'Binary: $'
HEX DB 0DH, 0AH, 'Hexadecimal: $'
OCTAL DB 0DH, 0AH, 'Octal: $'

D_DATA DB 10 DUP('$')   ;DECIMAL
B_DATA DB 10 DUP('$')   ;BINARY
H_DATA DB 10 DUP('$')   ;HEX
O_DATA DB 10 DUP('$')   ;OCTAL
 
.code

START:
    MOV AX, @data
    MOV DS, AX

    MOV DX, OFFSET DECIMAL
    MOV AH, 9H
    INT 21H

    MOV SI, OFFSET D_DATA
    MOV CX, 0

ENTER:
    MOV AH, 1H
    INT 21H
    INC CX

    MOV [SI], AL
    INC SI
   
    CMP AL, 0DH
    MOV DL, D_DATA
    MOV AX, 0
    JE  BIN1
    CMP CX, 2
    JNE ENTER
    MOV AL, 10
    MOV AH, 0
    MOV DL, D_DATA
    SUB DL, 30H
    MUL DL
    MOV DL, D_DATA + 1

BIN1:
    SUB DL, 20H
    ADD AL, DL
    PUSH AX
    MOV BX, 2
    MOV CX, 0

BINSOLV:
    MOV DX, 0
    DIV BX
    ADD DX, 48
    PUSH DX
    INC CX
    CMP AX, 0
    JNZ BINSOLV

    MOV SI, OFFSET B_DATA

BININPUT:
    POP AX
    MOV [SI], AL
    INC SI
    DEC CX

    JNZ BININPUT

    POP AX
    PUSH AX
    MOV BX, 8
    MOV CX, 0

HEX1:
    SUB DL, 20H
    ADD AL, DL
    PUSH AX
    MOV BX, 16
    MOV CX, 0
    
HEXSOLV:
    MOV DX, 0
    DIV BX
    ADD DX, 48
    PUSH DX
    INC CX
    CMP AX, 0
    JNZ HEXSOLV

    MOV SI, OFFSET H_DATA

HEXINPUT:
    POP AX
    MOV [SI], AL
    INC SI
    DEC CX

    JNZ HEXINPUT

    POP AX
    PUSH AX
    MOV BX, 8
    MOV CX, 0

OCT1:
    SUB DL, 20H
    ADD AL, DL
    PUSH AX
    MOV BX, 8
    MOV CX, 0    

OCTSOLV:
    MOV DX, 0
    DIV BX
    ADD DX, 48
    PUSH DX
    INC CX
    CMP AX, 0
    JNZ OCTSOLV

    MOV SI, OFFSET O_DATA

OCTINPUT:
    POP AX
    MOV [SI], AL
    INC SI
    DEC CX
    JNZ OCTINPUT

END:
    MOV AH, 9
    MOV DX, OFFSET BINARY
    INT 21H
    MOV AH, 9
    MOV DX, OFFSET B_DATA
    INT 21H 

    MOV AH, 9
    MOV DX, OFFSET HEX
    INT 21H
    MOV AH, 9
    MOV DX, OFFSET H_DATA
    INT 21H 

    MOV AH, 9 
    MOV DX, OFFSET OCTAL
    INT 21H
    MOV AH, 9
    MOV DX, OFFSET O_DATA
    INT 21H
                

ret
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • Does this answer your question? [Displaying characters with DOS or BIOS](https://stackoverflow.com/questions/44747002/displaying-characters-with-dos-or-bios) – Sep Roland Sep 18 '22 at 10:45

1 Answers1

0

The method to produce colored text is described in Displaying characters with DOS or BIOS. Under 'Full Screen Application', look for the code snippet that is labeled WriteStringWithAttributeTVM:. Include its code in your program and then change your output for octal numbers from

MOV AH, 9 
MOV DX, OFFSET OCTAL
INT 21H
MOV AH, 9
MOV DX, OFFSET O_DATA
INT 21H

to

mov  dx, OFFSET OCTAL
mov  ah, 09h 
int  21h
mov  bl, 4                       ; Red for octal
mov  si, OFFSET O_DATA
call WriteStringWithAttributeTVM

Because my subroutine uses zero-terminated strings, you need to change the buffer definition too:

O_DATA db 10 DUP(0)   ; OCTAL

Apply similar changes for the other number representations.


BIN1:
    SUB DL, 20H
    ADD AL, DL

You need to subtract 30h to convert.

HEX1:
    SUB DL, 20H
    ADD AL, DL

You need to subtract 30h to convert and DL got destroyed by the word-sized division in BINSOLV!

OCT1:
    SUB DL, 20H
    ADD AL, DL

You need to subtract 30h to convert and DL got destroyed by the word-sized divisions in BINSOLV and HEXSOLV!


I am still new to assembly language and I would want some pointers how to learn well

Well, don't just extract the code snippet that I told you about, but read the whole Q/A that I linked too.
There's also Displaying numbers with DOS, How buffered input works, and Inputting multi-radix multi-digit signed numbers with DOS that contain a lot of information...

Sep Roland
  • 33,889
  • 7
  • 43
  • 76