将ASCII值的数组打印为汇编语言8086中的字符串



我是汇编语言编码的新手,并且我正在尝试弄清楚我初始化一系列字母(在ASCII中)的位置,循环循环,然后将其打印到控制台窗口作为串联字符串。这就是我到目前为止的:

.MODEL flat
.DATA
    name1 DB 4Ah, 69h, 6Dh, 6Dh, 79h
.CODE
main        PROC
            mov ecx, 0
            mov esi, offset name1
loop1:      
            mov dl, [esi]
            mov ah, 2
            inc esi
            inc ecx
            cmp ecx, 5
            jne loop1
endlp:      
            mov eax, 4c00h
            ret
main        ENDP
END

我迷路了。我这里有一些试图帮助我的东西,很抱歉,如果看起来很混乱。

关于您的问题的一切哭泣。我建议您在这些简单的演示程序中使用 tiny 模型。

  • 在16位环境中,使用16位登记册是很自然的。
  • 要执行DOS API服务,您将请求的参数放在选定的寄存器中,然后将功能编号存储在AH寄存器中。然后您发出int 21h调用。
  • 更有效的循环将下降。通常,您可以避免在回路之前进行比较,因为标志已由dec指令设置。
  • 如果将程序的数据放置在退出DOS的代码下方,则避免错误地执行它。
  • 您可以将ASCII代码的数组更容易编写为字符串。请参阅第三个示例。


 ORG 256            ;This asks for the tiny model
 mov  cx, 5
 mov  si, offset array
again:      
 mov  dl, [si]
 mov  ah, 02h
 int  21h            ;Display character
 inc  si
 dec  cx
 jnz  again
 mov  ax, 4C00h
 int  21h            ;Exit the program
array db 4Ah, 69h, 6Dh, 6Dh, 79h

替代程序根本不使用CX计数器。当指针SI指向最后一个字符时,就足够停止了。

 ORG  256            ;This asks for the tiny model
 mov  si, offset array
again:      
 mov  dl, [si]
 mov  ah, 02h
 int  21h            ;Display character
 inc  si
 cmp  si, offset array+5
 jb   again
 mov  ax, 4C00h
 int  21h            ;Exit the program
array db 4Ah, 69h, 6Dh, 6Dh, 79h

另一个替代程序在数组上使用零分界符。要查看是否达到定界符,您可以编写cmp dl, 0 je exit,但更好的是编写test dl, dl jz exit

 ORG  256            ;This asks for the tiny model
 mov  si, offset array
again:      
 mov  dl, [si]
 test dl, dl         ;Test for zero delimiter
 jz   exit
 mov  ah, 02h
 int  21h            ;Display character
 inc  si
 jmp  again
exit:
 mov  ax, 4C00h
 int  21h            ;Exit the program
array db 'Jimmy', 0

最新更新