我試圖複製使用16位程序集的字符串。如何在x86程序集中將字符從一個內存位置複製到另一個內存位置?
我有(其中包括).dirBafer中的16個11位字符的字符串,我想將每個字符串複製到.ime_dat中,以便稍後打印並處理它(處理代碼尚未寫入)。每個字符串的第一個字符由32個字節的數據分隔。基本上.dirbafer是一個FAT12目錄的轉儲,我試圖打印文件名。
我有下面的代碼:
mov dx, .dirBafer ;loads address of .dirBafer in dx
mov cx, 16 ;16 entries in a dir
.load_dir:
push cx
mov ax, dx ;loads address of .dirBafer from dx into ax
mov bx, .ime_dat ;buffer for storing file names
mov cx, 11 ;each file name is 11 characters long
.ime_dat_str:
push dx ; push dx, since it's being used as a temporary register
mov dx, [ax] ;this is supposed to load first char from location pointed byax to dx
mov [bx], dx ;this is supposed to load the first char from location pointed by dx to bx
add ax, 1 ; moving on to the next character
add bx, 1 ;moving on to the next character
pop dx ; we pop the dx so that the original value returns
loop .ime_dat_str ;this should loop for every character in the file name
mov si, bx ;preparing to print the file name
call _print_string ; printing the name
add dx, 32 ; we move to the next dir entry
pop cx ; popping cx so that the outer look counter can be updated
loop .load_dir
.dirBafer times 512 db 0
.ime_dat times 12 db 0
我的問題是該行:
mov dx, [ax]
產生無效的有效地址錯誤。
我在做什麼錯,我該如何解決?
如果您查找系統ABI的暫存寄存器,它可能會有所幫助,因爲這些寄存器在通話期間(通常是EAX,ECX和EDX)不會被保留。 – Necrolis
@Necrolis在我的特殊情況下,他們是(好的,我正在使用的)。只是要清楚:如果他們不是,我會得到運行時錯誤,對吧?我在裝配過程中發生錯誤。 – AndrejaKo
啊,是啊,沒關係,在這裏晚了一點,我不是直讀:S,但是,仍然看看你的系統的ABI,它可能會幫助你從長遠來看:) – Necrolis