英文:
Getting errors while trying to output a string and set background color using TASM and DOSBox
问题
我正在测试一个TASM程序,用于设置背景颜色并输出字符串。但我遇到了错误。
.model small
.stack 100h
.data
prompt db 13, 10, 'Hello Gaiz!', '$'
.code
start:
call color ; 调用color过程来设置背景颜色
call output
mov ax, 4C00h ; 退出程序
int 21h
output proc
mov ah, 09h
lea dx, prompt
int 21h
ret
output endp
color proc
MOV AH, 06h ; 滚动屏幕函数
XOR AL, AL ; 清除整个屏幕
XOR CX, CX ; 左上角 CH=行, CL=列
MOV DX, 184FH ; 右下角 DH=行, DL=列
MOV BH, 42H ; 红色和绿色
INT 10H
ret
color endp
end start
运行时,出现随机字符和未正确执行。
英文:
I'm testing a TASM program to set the background color and output a string. But I'm having errors.
.model small
.stack 100h
.data
prompt db 13, 10, 'Hello Gaiz!', '$'
.code
start:
call color ; Call the color procedure to set the background color
call output
mov ax, 4C00h ; Exit program
int 21h
output proc
mov ah, 09h
lea dx, prompt
int 21h
ret
output endp
color proc
MOV AH, 06h ; Scroll up function
XOR AL, AL ; Clear entire screen
XOR CX, CX ; Upper left corner CH=row, CL=column
MOV DX, 184FH ; lower right corner DH=row, DL=column
MOV BH, 42H ; Red and Green
INT 10H
ret
color endp
end start
When run, random characters and not properly executed.
答案1
得分: 1
> mov ah, 09h
> lea dx, prompt
> int 21h
传递给DOS的指针实际上是DS:DX。不幸的是,你忘记在程序启动时初始化DS段寄存器。对于使用`small`模型的**.EXE程序**,DS默认将指向PSP(程序段前缀)。只需在程序旁边添加以下代码:
.code
start:
mov ax, @data ; 设置DS
mov ds, ax ;
call color
或者,保持更简单:
开始开发**.COM程序**。不需要设置段寄存器,因为它们在启动时都相等(CS=DS=ES=SS):
ORG 256
call color ; 调用颜色过程设置背景颜色
call output
mov ax, 4C00h ; 退出程序
int 21h
output:
mov ah, 09h
lea dx, prompt
int 21h
ret
color:
MOV AH, 06h ; 向上滚动功能
XOR AL, AL ; 清除整个屏幕
XOR CX, CX ; 左上角CH=行,CL=列
MOV DX, 184FH ; 右下角DH=行,DL=列
MOV BH, 42H ; 红色和绿色
INT 10H
ret
prompt db 13, 10, 'Hello Gaiz!', '$'
英文:
> mov ah, 09h
> lea dx, prompt
> int 21h
The pointer that you pass to DOS is actually DS:DX. Sadly, you forgot to initialize the DS segment register at program start. For this .EXE program using the small
model, DS by default will be pointing at the PSP (Program Segment Prefix). Just add next to your program:
.code
start:
mov ax, @data ; Setup DS
mov ds, ax ;
call color
Alternatively, keep it much simpler
Start developing .COM programs. No troubles with setting up segment registers as they start out equal to each other (CS=DS=ES=SS):
ORG 256
call color ; Call the color procedure to set the background color
call output
mov ax, 4C00h ; Exit program
int 21h
output:
mov ah, 09h
lea dx, prompt
int 21h
ret
color:
MOV AH, 06h ; Scroll up function
XOR AL, AL ; Clear entire screen
XOR CX, CX ; Upper left corner CH=row, CL=column
MOV DX, 184FH ; lower right corner DH=row, DL=column
MOV BH, 42H ; Red and Green
INT 10H
ret
prompt db 13, 10, 'Hello Gaiz!', '$'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论