如何用汇编语言打印竖排字符

how to print vertical character in assembly language

有一些方法可以使用循环垂直打印字符,例如在汇编语言中打印 'l' 从 (0,0) 到 (0,10)。我正在使用 emu8086。我的意思是在不更改列的情况下在不同的行中打印

org 100h

mov ax, 3
mov ah, 0
mov al, 3
int 10h         

mov cl,10
print:
mov ah,02 
mov bh,0                        
mov dh,cl  ;y
mov dl,0  ; x
int 10h 

mov ah,09  
mov bh,0     
mov bl,00Fh 
mov al,'l'
mov cx, 1  
int 10h 
loop print  

ret

mov ax, 3
mov ah, 0
mov al, 3

这些说明应该做什么?
我猜你忘了写 int 10h 来设置 80x25 文本视频模式?


你的程序中的基本错误(都包含在 Ped7g 的注释中)是你只将 CL 寄存器初始化为你的循环计数器,其中 loop 指令取决于整个 CX 注册,而且你错误地修改了它,以便你可以将 CX 用于第二个目的。


... print the 'l' from (0,0) to (0,10) ...

  • 为了获得高效的程序,您可以在循环之外放置尽可能多的指令。 CX中的重复次数、BH中的显示页面、BL中的显示属性、DL中的列在整个循环过程中都是不变的,因此可以放在外面。
  • 你也应该避免使用 loop 指令,因为现在它不是很快。
  • 当您需要将值放入像 ALAH 这样的字节大小的寄存器中时,您应该尽量使用字大小的 AX 寄存器在一次操作中完成.这同样适用于 BXCXDX 寄存器。

下一个代码应用上面的代码:

    ORG  256
    mov  ax, 0003h        ;BIOS.SetVideoMode AH=00h, Mode 80x25 AL=3
    int  10h
    mov  bx, 000Fh        ;Display page BH=0, Display attribute BL=0Fh
    mov  cx, 1            ;Repetition count CX=1
    mov  dx, 0A00h        ;Row DH=10, Column DL=0
print:
    mov  ah, 02           ;BIOS.SetCursor
    int  10h 
    mov  ax, 0900h + 'l'  ;BIOS.DisplayCharacter AH=09h, Character AL='l'
    int  10h
    dec  dh               ;Go one row up
    jns  print            ;Will stop when DH becomes -1
    ret                   ;Back to DOS (works for a .COM program)