Assuming I have a string of ascii characters such as "652+346*779=", and I want to move some characters FROM this variable TO another variable...
假设我有一串ascii字符,比如“652+346*779=”,我想把一些字符从这个变量移到另一个变量…
Buffer is the string (in this case "652+346*779=") lengthofnum is the length of the number in question (in this case 346 has length 3) A_ascii is the variable to which I'm trying to transport the string "346".
缓冲区是字符串(在本例中是“652+346*779=”),长度是问题的长度(在本例中,346有长度为3)A_ascii是我试图将字符串“346”传输的变量。
I have a loop that doesn't work at all, and I can't figure out what addressing mode I'm supposed to use. emu8086 hates everything I've tried so far, and gives me errors regarding my syntax with the MOV instruction
我有一个不工作的循环,我不知道应该使用什么寻址模式。emu8086讨厌我迄今为止尝试过的所有东西,并且在我的语法和MOV指令上犯了错误。
mov cx,lengthofnum
dumploop1:
mov bx, offset buffer
;dump the number from buffer into A_ascii
mov A_ascii[cx],[bx]+cx
loop dumploop1:
I get the following error codes:
我得到以下错误代码:
(672) wrong parameters: MOV A_ascii[cx],[bx]+cx
(672) probably it's an undefined var: A_ascii[cx]
2 个解决方案
#1
6
Contrary to (apparently) popular belief, you can do a direct mem->mem move on an x86, without (explicitly) moving to/from a register. Since you already have the length in CX, you're already started in the right direction:
与(显然)流行的想法相反,您可以直接在x86上运行mem->mem,而不需要(显式地)移动到寄存器。因为你已经有了CX的长度,你已经开始在正确的方向:
mov si, offset A_ascii
mov di, offset B_ascii
rep movsb ; automatically uses length from CX
#2
1
You can't directly move between two pointers. You need to move it into a register for temporary storage:
你不能直接在两个指针之间移动。你需要把它移动到一个临时存储寄存器:
mov dx, [bx+cx]
mov [A_ascii+cx], dx
If you've got two blocks of memory that you want to move, the usual method is something like this:
如果你有两个你想要移动的内存块,通常的方法是这样的:
xor cx, cx ; set counter = 0
mov ax, addressOfSource ; load base addresses
mov bx, addressOfDest
move_loop:
mov dx, [ax+cx] ; load 2 bytes of data from source
mov [bx+cx], dx ; move data into dest
add cx, 2 ; increment counter
cmp cx, dataLength ; loop while counter < length
jl move_loop
#1
6
Contrary to (apparently) popular belief, you can do a direct mem->mem move on an x86, without (explicitly) moving to/from a register. Since you already have the length in CX, you're already started in the right direction:
与(显然)流行的想法相反,您可以直接在x86上运行mem->mem,而不需要(显式地)移动到寄存器。因为你已经有了CX的长度,你已经开始在正确的方向:
mov si, offset A_ascii
mov di, offset B_ascii
rep movsb ; automatically uses length from CX
#2
1
You can't directly move between two pointers. You need to move it into a register for temporary storage:
你不能直接在两个指针之间移动。你需要把它移动到一个临时存储寄存器:
mov dx, [bx+cx]
mov [A_ascii+cx], dx
If you've got two blocks of memory that you want to move, the usual method is something like this:
如果你有两个你想要移动的内存块,通常的方法是这样的:
xor cx, cx ; set counter = 0
mov ax, addressOfSource ; load base addresses
mov bx, addressOfDest
move_loop:
mov dx, [ax+cx] ; load 2 bytes of data from source
mov [bx+cx], dx ; move data into dest
add cx, 2 ; increment counter
cmp cx, dataLength ; loop while counter < length
jl move_loop