gpt4 book ai didi

程序集 8086 - 将一个缓冲区复制到另一个缓冲区

转载 作者:行者123 更新时间:2023-12-02 06:53:48 28 4
gpt4 key购买 nike

我正在开发一个汇编程序,该程序将整个文本文件读入缓冲区,然后将其显示在控制台中。它立即显示 24 行(每行的最大长度为 80,因为我使用 80 宽 * 25 高的 dossbox )然后等待用户输入,以便用户可以滚动浏览文本。

我想将行号添加到每行的开头,所以我想我可以制作第二个缓冲区并从第一个缓冲区复制字符 1by1,当我找到换行符时,我会调用一个将行号添加到缓冲区,然后继续,直到我继续通过整个缓冲区。但是我从一个缓冲区复制到另一个缓冲区的方式很糟糕。

所以我想复制
BUFFA 到 BUFFB:

mov di,OFFSET BUFFB ;so i set di to the beggining of bufferB




mov si,Pos ;Pos is my position in the first buffer
lea bx,BUFFA[si] ;move the content of buffA to bx , i think the problem is here
mov [di],bx ;move to the addres of di the content of bx
inc di
inc Pos

问题是当我打印出第二个缓冲区的内容时,我发现我将 si 的值(与 Pos 相同)复制到我的缓冲区而不是缓冲区 A [si] 的内容。我该如何修复此代码?

编辑1:

所以解决方案是使用 mov 和 al 寄存器:
mov si,Pos
mov al,[BUFF + si]
mov [di],al
inc di

最佳答案

您可以使用

lodsb

代替
mov al,[si]
inc si


stosb

代替
mov [di],al
inc di

在最好的情况下,您可以将两者结合起来
movsb    ; move byte at [si] to [di], and increase both indices

如果您知道要复制多少字节,您甚至可以使用“rep”移动内存块,该指令在 CX 次之后重复该指令:
cld                    ; make sure that movsb copies forward
mov si, source_buffer
mov di, dest_buffer
mov cx, #amount of bytes to copy
rep movsb

或填充内存块
cld                  ; make sure that stosb moves forward
mov si, buffer ; start here
mov al, 0xFF ; fill with 0xFF
mov cx, #20 ; 20 times
rep stosb

如果您使用单词而不是字节,请使用 lodsw、stosw 和 movsw

当方向标志被清除(通过 CLD)或向后(DEC si/di)时,所有这些指令都可以前进(INC si/di)。设置方向标志时(通过 STD)

关于程序集 8086 - 将一个缓冲区复制到另一个缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36142905/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com