颜色 0-15 组装
Colors 0-15 Assembly
晚安,
我正在尝试用程序集 (FASM) 做一个项目,我需要做一些三角形并放置 0 到 15 之间的 2 种颜色(向使用该程序的人询问数字)
我得到这个 "read" 值:
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
但这只允许我从 0 读到 9,谁能帮我把它从 0 读到 15?
您可以要求用户输入十六进制数字 A-F 来表示颜色 10-15。这对您的程序施加的更改最少。
改变这个
sub [color1], 48
sub [color2], 48
进入
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
同时通过更改提示让用户知道。
color1msg db "Defina a cor 1 (0-9 A-F): "
color2msg db "Defina a cor 2 (0-9 A-F): "
mov ah, 3Fh
mov bx, 0
mov cx, 2
mov dx, crlf
int 21h
为了能够响应 2 位数的输入,您需要进行测试以确定之前的代码是否确实获得了字节 13 和 10。我建议如下
...
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
; - - - - - - - - - -
sub [color1],48
mov ax, [crlf]
cmp ax, 0A0Dh
je OneDigit
TwoDigits:
sub al, 48
mov ah, [color1]
aad ; AL=AH*10+AL
mov [color1], al
mov ah, 3Fh ; Fetch the still pending linefeed from DOS
mov bx, 0
mov cx, 1
mov dx, crlf
int 21h
OneDigit:
编辑
完成的程序如下。这应该解决评论中表达的担忧。
mov ah, 40h
mov bx, 1
mov cx, 23
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
sub BYTE [color1], 48
mov al, BYTE [crlf]
cmp al, 13
je OneDigit_1
TwoDigits_1:
sub al, 48
mov ah, [color1]
aad ; AL=AH*10+AL
mov [color1], al
mov ah, 3Fh ; Fetch the still pending linefeed from DOS
mov bx, 0
mov cx, 1
mov dx, crlf
int 21h
OneDigit_1:
mov ah, 40h
mov bx, 1
mov cx, 1
mov dx, paragrafo
int 21h
mov ah, 40h
mov bx, 1
mov cx, 23
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
sub BYTE [color2], 48
mov al, BYTE [crlf]
cmp al, 13
je OneDigit_2
TwoDigits_2:
sub al, 48
mov ah, [color2]
aad ; AL=AH*10+AL
mov [color2], al
mov ah, 3Fh ; Fetch the still pending linefeed from DOS
mov bx, 0
mov cx, 1
mov dx, crlf
int 21h
OneDigit_2:
mov ah, 40h
mov bx, 1
mov cx, 1
mov dx, paragrafo
int 21h
...
color1msg db "Defina a cor 1 (0-15): "
color2msg db "Defina a cor 2 (0-15): "
paragrafo db 10
crlf rb 2
color1 rb 1
color2 rb 1
晚安,
我正在尝试用程序集 (FASM) 做一个项目,我需要做一些三角形并放置 0 到 15 之间的 2 种颜色(向使用该程序的人询问数字)
我得到这个 "read" 值:
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
但这只允许我从 0 读到 9,谁能帮我把它从 0 读到 15?
您可以要求用户输入十六进制数字 A-F 来表示颜色 10-15。这对您的程序施加的更改最少。
改变这个
sub [color1], 48
sub [color2], 48
进入
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
同时通过更改提示让用户知道。
color1msg db "Defina a cor 1 (0-9 A-F): "
color2msg db "Defina a cor 2 (0-9 A-F): "
mov ah, 3Fh
mov bx, 0
mov cx, 2
mov dx, crlf
int 21h
为了能够响应 2 位数的输入,您需要进行测试以确定之前的代码是否确实获得了字节 13 和 10。我建议如下
...
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
; - - - - - - - - - -
sub [color1],48
mov ax, [crlf]
cmp ax, 0A0Dh
je OneDigit
TwoDigits:
sub al, 48
mov ah, [color1]
aad ; AL=AH*10+AL
mov [color1], al
mov ah, 3Fh ; Fetch the still pending linefeed from DOS
mov bx, 0
mov cx, 1
mov dx, crlf
int 21h
OneDigit:
编辑
完成的程序如下。这应该解决评论中表达的担忧。
mov ah, 40h
mov bx, 1
mov cx, 23
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
sub BYTE [color1], 48
mov al, BYTE [crlf]
cmp al, 13
je OneDigit_1
TwoDigits_1:
sub al, 48
mov ah, [color1]
aad ; AL=AH*10+AL
mov [color1], al
mov ah, 3Fh ; Fetch the still pending linefeed from DOS
mov bx, 0
mov cx, 1
mov dx, crlf
int 21h
OneDigit_1:
mov ah, 40h
mov bx, 1
mov cx, 1
mov dx, paragrafo
int 21h
mov ah, 40h
mov bx, 1
mov cx, 23
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
sub BYTE [color2], 48
mov al, BYTE [crlf]
cmp al, 13
je OneDigit_2
TwoDigits_2:
sub al, 48
mov ah, [color2]
aad ; AL=AH*10+AL
mov [color2], al
mov ah, 3Fh ; Fetch the still pending linefeed from DOS
mov bx, 0
mov cx, 1
mov dx, crlf
int 21h
OneDigit_2:
mov ah, 40h
mov bx, 1
mov cx, 1
mov dx, paragrafo
int 21h
...
color1msg db "Defina a cor 1 (0-15): "
color2msg db "Defina a cor 2 (0-15): "
paragrafo db 10
crlf rb 2
color1 rb 1
color2 rb 1