彩色的Hello World在TASM [英] Colored Hello World in TASM

查看:292
本文介绍了彩色的Hello World在TASM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天。我在汇编语言新我想在TASM打印彩色的Hello World。这里是我的code为止。它只是输出Hello World没有颜色。结果

  .MODEL小
.STACK 100H。数据
消息分贝13,10,的Hello World!$。code
主要PROC附近
   LEA DX,消息
   MOV啊,09H
   INT 21H   MOV啊,4路
   INT 21H
主要ENDP

结果
我读过这样的结果。

  MOV啊,9;功能9:写在光标所在位置的性格和属性
MOV人,'H'; AL =字符显示
MOV BH,0; BH =页码
MOV BL,02EH; BL =属性(在绿黄)
MOV CX,1; CX =次写入字符数
INT 10H;诠释10H:视频(显示的字符)

结果在一个论坛上,但我不能用我的Hello World其纳入。我很困惑,为什么用特定的寄存器等。请帮帮我。非常感谢您!搜索结果

修改搜索结果

  .MODEL小
.STACK 100H。数据
你好分贝的'Hello World!,0。code
主要PROC附近
    MOV AX,@data
    MOV DS,AX    MOV AX,3
    INT 10H    MOV SI,0; CL为计数寄存器,将其设置为
                      ;零(字符串中的第一个字符)开始:;循环的开始
    MOV人,你好[SI];从存储器读下一字节
    CMP人,0;比较字节为空(终止)
    JE endthis;如果字节为null,跳出循环    MOV啊,09H
    MOV人,你好[SI]
    MOV BH,0
    MOV BL,02EH
    MOV CX,11
    INT 10H    加SI,1;移动到下一个字节串中
    JMP启动;循环endthis:
    MOV啊,4路
    INT 21H主要ENDP
最终主


解决方案

汇编语言,因为任何编程语言,是任意的设计决策的结果。有时可为什么一个特定的寄存器用作中断调用输入寄存器(优化)的一个原因,但不是很多时候,你不得不走接口(这里 INT 10H INT 21H )的批准。

与您问题相关的几个感叹号 !!!!!!!!!!! (我假设11感叹号),你有不正确的参数的 10 INT 中断调用:

  MOV CX,11

根据拉尔夫·布朗的中断列表,参数为 MOV啊9 INT 10H 如下:

  10 INT  - 视频 - 写本质及属性指针位置
    AH = 09H
    AL =字符显示
    BH =页码(00h至页数 - 1)(见#00010)
        背景色256色图形模式(ET4000)
    BL =属性(文本模式)或彩色(图形模式)
        如果第7位设置上述< 256色图形模式,特点是异或
          到屏幕
    CX =次写入字符数
返回:无
注:所有字符显示,包括CR,LF和BS
    在CX复制计数可能产生图形的未predictable结果
      模式,如果它是比位置中剩余的数量大于
      当前行
    与PhysTechSoft的PTS ROM-DOS中的BH,BL和CX值被忽略
      入境。

所以,相反的 MOV CX,11 ,它应该是 MOV CX,1

和第二 MOV人,你好[SI] 是多余的,因为你好[SI] 已是装入当时的previous相同的指令。这并不影响code的运作,然而

编辑:如何设置和使用读光标位置 INT 10H 补充信息

看来你还需要更新的光标位置 MOV啊,2 INT 10H ,使用以下参数:

  10 INT  - 视频 - 调整光标位置
    AH = 02H
    BH =页码
        0-3在模式2和3
        0-7模式0放大器1
        0图形模式
    DH =行(00H是顶部)
    DL =列(00H是左)
返回:无

也许你可能需要需要阅读与 MOV啊,在当前光标位置3 INT 10H ,使用以下参数:

  10 INT  - 视频 - 读取游标位置和大小
    AH = 03H
    BH =页码
        0-3在模式2和3
        0-7模式0放大器1
        0图形模式
返回:AX = 0000H(菲尼克斯BIOS)
    CH =启动扫描线
    CL =结束扫描线
    DH =行(00H是顶部)
    DL =列(00H是左)
注意:一个单独的光标被维持为每个多达8显示页面的
    许多ROM的BIOS错误地返回默认大小的彩色显示屏
      (开始06H,07H结束)时单色显示器连接
    随着PhysTechSoft的PTS ROM-DOS的BH值入境忽略。

Good day. I'm new in assembly language and I'm trying to print a colored "Hello World" in TASM. Here is my code so far. It just prints "hello world" without a color.

.model small
.stack 100h

.data
message db 13,10,"Hello World!$"

.code
main proc near
   lea dx, message
   mov ah, 09h
   int 21h

   mov ah,4ch
   int 21h
main endp


I've read something like this

mov ah,9    ;Function 9: Write character and attribute at cursor position
mov al,'H'  ;AL = character to display
mov bh,0    ;BH = page number
mov bl,02EH ;BL = attribute (yellow on green)
mov cx,1    ;CX = number of times to write character
int 10H  ;Int 10H: Video (show the character)


in a forum but I can't incorporate it with my hello world. I'm confused why use that particular register and the like. Please help me. Thank you very much!

EDIT

.model small
.stack 100h

.data
hello db 'Hello World!',0

.code
main proc near
    mov ax, @data
    mov ds, ax

    mov ax, 3
    int 10h

    mov si, 0             ; cl is the counter register, set it to
                      ; zero (the first character in the string)

start:                ; Beginning of loop
    mov al, hello[si]   ; Read the next byte from memory
    cmp al, 0           ; Compare the byte to null (the terminator)
    je endthis              ; If the byte is null, jump out of the loop

    mov ah, 09h
    mov al, hello[si]
    mov bh, 0
    mov bl,02EH
    mov cx,11
    int 10H  

    add si, 1           ; Move to the next byte in the string
    jmp start           ; Loop

endthis:    
    mov ah, 4ch
    int 21h

main endp
end main

解决方案

Assembly language, as any programming language, is a result of arbitrary design decisions. Sometimes there can be a reason why a specific register is used as a interrupt call input register (optimization), but many times not, and you just have to take the interface (here int 10h or int 21h) as granted.

Related to your problem with several exclamation marks !!!!!!!!!!! (I assume 11 exclamation marks), you have incorrect parameters in your int 10 interrupt call:

mov cx,11

According to Ralf Brown's Interrupt List, the parameters for mov ah,9, int 10h are the following:

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.

So, instead of mov cx,11, it should be mov cx,1.

And the second mov al, hello[si] is redundant, because hello[si] has already been loaded into al at that time with the previous identical instruction. This doesn't affect the functioning of the code, however.

Edit: Added info on how to set and read the cursor location using int 10h.

It seems that you also need to update the cursor location with mov ah,2, int 10h, using the following parameters:

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)
Return: nothing

Possibly you may need need to read the current cursor position with mov ah,3, int 10h, using the following parameters:

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.

这篇关于彩色的Hello World在TASM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆