Assembly 8086 - copy one buffer to another

末鹿安然 提交于 2019-12-03 21:19:02
Tommylee2k

you can use

lodsb

instead of

mov al,[si]
inc si

and

stosb

instead of

mov [di],al
inc di

in best cases, you can combine both to

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

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

or fill memory blocks

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

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

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)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!