程序集8086-将一个缓冲区复制到另一个 [英] Assembly 8086 - copy one buffer to another

查看:98
本文介绍了程序集8086-将一个缓冲区复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

im working on a assembly program that reads the whole text file into a buffer then displays it in the console. It displays 24 lines (each line has a max lenght of 80, because im using a 80 wide * 25 height dossbox ) at once then waits for user input so the user can scroll through the text.

我想将行数添加到每行的开头,所以我想可以制作第二个缓冲区,并从第一个缓冲区复制chars 1by1,当我找到换行符时,我将调用一个过程来添加行编号到缓冲区,然后继续直到我继续遍历整个缓冲区.但是我从一个缓冲区复制到另一个缓冲区的方法很糟糕.

I wanted to add the number of line to the beginning of each line, so figured i could make a second buffer and copy chars 1by1 from the first one and when i find a newline i would call a procedure which would add the line number to the buffer, then continue till i proceed thru the whole buffer. But my way of copying from one buffer to the other is bad.

所以我想复制 BUFFA到BUFFB:

So i wanna copy BUFFA to 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]的内容中.我该如何解决此代码?

the problem is when i print out the content of the second buffer i find out that i copy the value of si(same as Pos) to my buffer and not the content of the bufferA[si]. How can i fix this code?

所以解决方案是使用mov和al寄存器:

So the solution is using mov and al register:

mov si,Pos
mov al,[BUFF + si]
mov [di],al
inc di

推荐答案

您可以使用

lodsb

代替

mov al,[si]
inc si

stosb

代替

mov [di],al
inc di

在最佳情况下,您可以将两者结合在一起

in best cases, you can combine both to

movsb    ; move byte at [si] to [di], and increase both indices

如果您知道要复制多少字节,甚至可以使用"rep"来移动内存块,该命令将在CX次之后重复该指令:

if you know how many bytes to copy, you can even move memory blocks using "rep", which repeats the instruction afterwards CX times:

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

if you're using words instead of bytes, use lodsw, stosw and movsw

所有这些指令可以在清除方向标志(通过CLD)时前进-(INC si/di),也可以在
后退(DEC si/di)前进.设置方向标志时(通过STD)

All these instructions can either go
- forward (INC si/di) when the direction flag is cleared (via CLD) or
- backwards (DEC si/di). when the direction flag is set (via STD)

这篇关于程序集8086-将一个缓冲区复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆