在TASM /组件中原样打印彩色字符串,例如13作为回车符,而不是垃圾值

时间:2013-03-10 17:07:18

标签: string assembly colors x86 tasm

美好的一天!我是汇编语言的新手,我正在尝试打印一个带有颜色的简单“Hello World”。它可以工作,但是当我现在添加13, 10时,它不显示回车换行但显示其他字符(音符和圆圈)。这是我的代码:

.MODEL SMALL
.DATA
.stack

hello db 13,10,'Hello World'
      db 13,10,'    #####     ',0        ; there are spaces
ROW1 DB 12
COL DB 20

.CODE
.STARTUP
MOV AL, 3       ; 80x25 color
INT 10H         ; video BIOS call   
MOV AH, 2       ; set cursor position
MOV BH, 0       ; display page number
 mov bl,2
MOV DH, ROW1        ; row number
MOV DL, COL     ; column number
INT 10H         ; video BIOS call
CALL FAR PTR DISP   ; display first line of video text

.EXIT

DISP PROC FAR
        MOV SI, 0   ; set up array pointer
NEXT:   MOV AL, hello[SI]; get name character
    CMP AL, 0   ; exit if character is 0
    JZ EXIT     
    MOV BH, 0   ; display page number
    MOV BL, [BP+SI] ; get attribute
    MOV CX, 1   ; do 1 character
    MOV AH, 9   ; write character/attribute on screen
    INT 10H     ; video BIOS call
    INC SI      ; point to next character/attribute
    ADD DL, 1   ; move two columns to the right
    MOV AH, 2   ; set cursor position
    INT 10H     ; video BIOS call
    JMP NEXT    ; and continue
EXIT:   RET
DISP ENDP

END


请帮我修复代码,以便在控制台中看到hello变量中写的 。另外,我怎样才能摆脱闪烁的颜色?我只是在互联网上有一个颜色列表,但是当我在这里输入它时,它会闪烁(mov bl, 2为绿色,但它会闪烁)。

2 个答案:

答案 0 :(得分:0)

当我回答你的另一个问题时,来自Ralf Brown's Interrupt List

INT 10 - VIDEO - WRITE CHARACTER AND ATTRIBUTE AT CURSOR POSITION
    AH = 09h
    AL = character to display
    BH = page number (00h to number of pages - 1) (see #00010)
        background color in 256-color graphics modes (ET4000)
    BL = attribute (text mode) or color (graphics mode)
        if bit 7 set in <256-color graphics mode, character is XOR'ed
          onto screen
    CX = number of times to write character
Return: nothing
Notes:  all characters are displayed, including CR, LF, and BS
    replication count in CX may produce an unpredictable result in graphics
      modes if it is greater than the number of positions remaining in the
      current row
    With PhysTechSoft's PTS ROM-DOS the BH, BL, and CX values are ignored
      on entry.

正如它所说:注意:显示所有字符,包括CR,LF和BS

您必须自己解释运营商退货(CR,0x0d)。因此,如果输入为0x0d(十进制为13),请执行以下说明,否则如果输入为其他内容,请按照当前的处理方式处理。

因此,对于CR,请读取当前光标位置,然后使用以下int 10h调用更改光标位置:

首先,获取当前光标位置:

INT 10 - VIDEO - GET CURSOR POSITION AND SIZE
    AH = 03h
    BH = page number
        0-3 in modes 2&3
        0-7 in modes 0&1
        0 in graphics modes
Return: AX = 0000h (Phoenix BIOS)
    CH = start scan line
    CL = end scan line
    DH = row (00h is top)
    DL = column (00h is left)
Notes:  a separate cursor is maintained for each of up to 8 display pages
    many ROM BIOSes incorrectly return the default size for a color display
      (start 06h, end 07h) when a monochrome display is attached
    With PhysTechSoft's PTS ROM-DOS the BH value is ignored on entry.

在输出中,dh是当前行。那么inc dh然后设置其余参数:

INT 10 - VIDEO - SET CURSOR POSITION
    AH = 02h
    BH = page number
        0-3 in modes 2&3
        0-7 in modes 0&1
        0 in graphics modes
    DH = row (00h is top)
    DL = column (00h is left)

但是,当你在底行并且输入中有CR时,你没有在你的问题中说出你想做什么。您也应该检查这种情况并按照您喜欢的方式处理。

然后:

inc si
jmp next

答案 1 :(得分:0)

您可以将function 0Eh用于CRLF。它将使光标位置前进:

  

视频 - TELETYPE输出

     

AH = 0Eh
  AL =要写的字符
  BH =页码
  BL =前景色(仅限图形模式)

     

描述:在屏幕上显示一个字符,推进光标并根据需要滚动屏幕

     

注意:字符07h(BEL),08h(BS),0Ah(LF)和0Dh(CR)被解释并执行预期的事情