匯編語言功能實現(xiàn)數(shù)據(jù)復(fù)制實例詳解
問題1:將內(nèi)存ffff:0~ffff:b單元中的數(shù)據(jù)復(fù)制到0:200~0:20b單元中
分析
1、0:200~0:20b單元如何表示
0020:0~0020:b可以等同于以上單元,而且單元的偏移地址是從0開始,和需要復(fù)制的單元相同
2、單元中的數(shù)據(jù)能直接進行復(fù)制轉(zhuǎn)移嗎
不可以,需要用寄存器進行中轉(zhuǎn)
assume cs:code code segment ;做法一 ;----------------------------- mov bx,0 ;因為數(shù)據(jù)來源和去處的偏移地址相同,用bx同意代替 mov cx,12 s: mov ax,offffh ;因為需要重復(fù)利用ax,所以需要循環(huán)設(shè)置 mov ds,ax mov dl,ds:[bx] ;將數(shù)據(jù)復(fù)制到dx的低8位中 mov ax,0020h mov ds,ax mov ds:[bx],dl ;將數(shù)據(jù)復(fù)制到指定的內(nèi)存單元中 inc bx ;向下一個單元移動 loop s ;----------------------------- ;做法二,上一個做法需要重復(fù)設(shè)置ds,這里可改進 ;----------------------------- mov ax,0ffffh mov ds,ax mov ax 0020h mov es,ax mov bx,0 mov cx,12 s: mov dl,ds:[bx] mov es:[bx],dl inc bx loop s ;----------------------------- mov ax,4c00h int 21h code ends end
問題2:將“mov ax,4c00h“之前的指令復(fù)制到內(nèi)存0:200處
分析:
1、如何知道代碼的起始地址
利用cs指向的就是代碼的開始地址
2、如何知道代碼的長度
可以使用(offset 標號)之間相減得出代碼的長度
assume cs:code code segment start: mov ax,cs mov ds,ax mov ax,0020h mov es,ax ;設(shè)置復(fù)制數(shù)據(jù)的來源和去處 mov bx,0 mov cx,offset last-offset start ;設(shè)置代碼的長度 s: mov al,ds:[bx] mov es:[bx],al ;實現(xiàn)數(shù)據(jù)的轉(zhuǎn)移 inc bx last: loop s mov ax,4c00h int 21h code ends end
問題3:將程序中定義的數(shù)據(jù)逆序存放
分析: 如何實現(xiàn)逆序 利用棧的特性實現(xiàn)
assume cs:code code segment dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h dw 16 dup(0) ;??臻g的使用 start: mov ax,cs mov ss,ax mov sp,30h ;棧空間是從后往前添加,棧頂指向30h mov bx,0 mov cx,8 s: push cs:[bx] add bx,2 loop s ;將數(shù)據(jù)段中的0~15單元中的數(shù)據(jù)壓入棧中 mov bx,0 mov cx,8 s0: pop cs:[bx] add bx,2 loop s0 ;依次出棧8個字型數(shù)據(jù) mov ax,4c00h int 21h code ends end start
改進版:以上程序中的內(nèi)容沒有分段存儲,可改進
assume cs:code,ds:data,ss:stack date segment dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h date ends stack segment dw 16 dup(0) ;??臻g的使用 stack ends code segment start: mov ax,stack mov ss,ax mov sp,20h ;棧開始的地址已經(jīng)不包括data段的內(nèi)容,則為20h mov ax,data mov ds,ax mov bx,0 mov cx,8 s: push ds:[bx] add bx,2 loop s mov bx,0 mov cx,8 s0: pop ds:[bx] add bx,2 loop s0 mov ax,4c00h int 21h code ends end start
問題4:將字符串”welcome to masm”復(fù)制到它后面的數(shù)據(jù)區(qū)中
分析
1、要復(fù)制到數(shù)據(jù)在哪里
數(shù)據(jù)的起始地址在data:0
2、要復(fù)制到哪里去
復(fù)制的數(shù)據(jù)長度是16個字節(jié),后面的數(shù)據(jù)區(qū)的偏移地址就是16
3、一共復(fù)制了幾次
因為使用的是16位寄存器,一次可以傳輸兩個字節(jié),所以只需要執(zhí)行8次
assume cs:code,ds:data data segment db 'welcome to masm!' db 16 dup(0) data ends ;---------------------------------- ;做法一 code segment start: mov ax,data mov ds,ax mov si,0 ;設(shè)置數(shù)據(jù)來源的起始位置 mov di,16 ;設(shè)置數(shù)據(jù)去處的起始位置 mov cx,8 ;用寄存器進行復(fù)制,只需要8次 s: mov ax,ds:[si] mov ds:[di],ax add si,2 add di,2 loop s mov ax,4c00h int 21h code ends ;---------------------------------- ;做法二:只利用一個寄存器就可以實現(xiàn) code segment start: mov ax,data mov ds,ax mov si,0 mov cx,8 s: mov ax,ds:[si] mov ds:[si+16],ax add si,2 loop s mov ax,4c00h int 21h code ends end start
以上就是匯編語言功能實現(xiàn)數(shù)據(jù)復(fù)制實例詳解的詳細內(nèi)容,更多關(guān)于匯編語言實現(xiàn)數(shù)據(jù)復(fù)制的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
詳解匯編語言RCL(帶進位循環(huán)左移)和RCR(帶進位循環(huán)右移)指令
這篇文章主要介紹了匯編語言RCL(帶進位循環(huán)左移)和RCR(帶進位循環(huán)右移)指令的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2020-01-01匯編語言DOSBox及debug.exe在Windows64下環(huán)境搭建
這篇文章主要為大家介紹了匯編語言環(huán)境的搭建DOSBox及debug.exe在Windows64下安裝配置過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-11-11