Search code examples
assemblyfasm

Colors 0-15 Assembly


Good night,

I'm trying to do a project with assembly(FASM), where i need to do some triangles and put 2 colors from 0 to 15 (ask the number to the human using the program)

i got this to "read" the values:

    mov ah, 40h
    mov bx, 1
    mov cx, 22
    mov dx, color1msg
    int 21h

    mov ah, 3Fh
    mov bx, 0
    mov cx, 1
    mov dx, color1
    int 21h

    mov ah, 3Fh
   mov bx, 0
   mov cx, 2
   mov dx, crlf
   int 21h

   mov ah, 40h
   mov bx, 1
   mov cx, 1
   mov dx, paragrafo
   int 21h

   mov ah, 40h
   mov bx, 1
   mov cx, 22
   mov dx, color2msg
   int 21h

   mov ah, 3Fh
   mov bx, 0
   mov cx, 1
   mov dx, color2
   int 21h

   mov ah, 3Fh
   mov bx, 0
   mov cx, 2
   mov dx, crlf
   int 21h

   mov ah, 40h
   mov bx, 1
   mov cx, 1
   mov dx, paragrafo
   int 21h  

   sub [color1], 48
   sub [color2], 48  


   color1msg db "Defina a cor 1 (0-9): "   ;insert the color one 0-9
   color2msg db "Defina a cor 2 (0-9): "     
   paragrafo db 10 
   crlf rb 2 
   color1 rb 2
   color2 rb 2    

but this only allows me to read from 0 to 9, can anyone help me puting this from 0 to 15 please?


Solution

  • You could ask the user to input the hexadecimal digits A-F to represent the colors 10-15. This imposes the least changes to your program.
    Change this

    sub [color1], 48
    sub [color2], 48  
    

    into

    mov al,[color1]
    cmp al,65
    jbe tt1   ;0-9
    sub al,7  ;A-F
    tt1:
    sub al,48
    mov [color1],al
    
    mov al,[color2]
    cmp al,65
    jbe tt2   ;0-9
    sub al,7  ;A-F
    tt2:
    sub al,48
    mov [color2],al
    

    Also let the user know by changing the prompts.

    color1msg db "Defina a cor 1 (0-9 A-F): "
    color2msg db "Defina a cor 2 (0-9 A-F): "