谁能帮帮我?我是汇编的新手,我必须做以下事情:
编写一个汇编语言程序,允许您从键盘输入两行不超过50个字符。并以适当的颜色显示以下几组字符:两个术语的通用字符(红色),第一行中不在第二行中的字符(蓝色),第二行中不在第一行中的字符(黄色)
我已经完成了第一部分,但是我不知道如何改变文本的颜色。
.model small
.data
message1 db "Enter any string: $"
message2 db "Given string is :$"
str1 db 50 dup('$')
str2 db 25 dup('$')
.code
mov ax,@data
mov ds,ax
;--------------------------------------------------
; disply first massege:
mov dx,offset message1 ; Enter any string:
mov ah,09h
int 21h
;adding new line
;--------------------------------------------------
call new_line
;--------------------------------------------------
;fist strig up to 25 char
firstString:
lea dx, str1
mov str1,26
mov ah,10
int 21h
;adding new line
;--------------------------------------------------
call new_line
;--------------------------------------------------
;second string up to 25 char
lea dx, str2
mov str2,26
mov ah,10
int 21h
;adding new line
;--------------------------------------------------
call new_line
;disply the input
;--------------------------------------------------
mov dx,offset message2
mov ah,09h
int 21h
;adding new line
;--------------------------------------------------
call new_line
;first string
;------------
mov cl,str1[1]
mov si,2
Output:
mov dl,str1[si]
mov ah,2
int 21h
inc si
loop output
;adding new line
;--------------
call new_line
;second string
;-------------
mov cl,str2[1]
mov si,2
Output2:
mov dl,str2[si]
mov ah,2
int 21h
inc si
loop output2
exit:
mov ah,4ch
int 21h
new_line proc near
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
ret
new_line endp
end
我尝试使用下一个代码,但它不工作:
mov si, 2
mov ch, 25 ;I have the max 25 char so I figured that I need to loop 25 times
color:
MOV AH,09 ; FUNCTION 9
MOV AL,str1[si] ; here i think i need to move my first element
MOV BX,0004 ; PAGE 0, COLOR 4
MOV Cl,1 ; here I don't know how many elements I have because i take input from the user
inc si
INT 10H ; INTERRUPT 10 -> BIOS
INT 20H
loop color ; END
你的尝试方向是正确的,但有一些缺陷。
- 您的
loop color
指令依赖于整个16位寄存器CX,因此设置mov ch, 25
是不够的!使用mov cx, 25
因为你的循环是由CX寄存器控制的,所以你不能在内部使用CL来处理其他的,除非你以某种方式保留的值。。 INT 20H
指令根本不属于这个循环!- 带颜色的输出不移动光标。你需要额外做这个。一种简单的方法是使用BIOS。电传打字功能0Eh.
mov si, 2
mov cx, 25
mov bx, 0004h ; Page 0, Color RedOnBlack
color:
push cx ; (1) Preserve CX
mov cx, 1 ; Repetition count
mov al, str1[si]
inc si
mov al, 09h
int 10h ; INTERRUPT 10 -> BIOS
mov ah, 0Eh
int 10h
pop cx ; (1) Restore CX
loop color
一个不需要保留CX的替代方案,因为我们可以使用DX来控制循环:
mov si, 2
mov dx, 25
mov cx, 1 ; Repetition count
mov bx, 0004h ; Page 0, Color RedOnBlack
color:
mov al, str1[si]
inc si
mov al, 09h
int 10h ; INTERRUPT 10 -> BIOS
mov ah, 0Eh
int 10h
dec dx
jnz color