Getting errors while trying to output a string and set background color using TASM and DOSBox.

huangapple go评论57阅读模式
英文:

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!', '$'

huangapple
  • 本文由 发表于 2023年5月25日 10:00:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76328421.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定