晚安,
我试图用汇编(FASM)做一个项目,我需要做一些三角形并放置0到15的2种颜色(使用程序向人类询问数字)
我得到了这个"阅读"价值观:
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吗?
答案 0 :(得分:2)
您可以要求用户输入十六进制数字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): "
答案 1 :(得分:2)
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