8086 汇编:将字符串的一部分 MOV 到变量中

发布于 2024-12-18 10:09:23 字数 574 浏览 5 评论 0原文

假设我有一串 ascii 字符,例如“652+346*779=”,并且我想将一些字符从这个变量移动到另一个变量...

缓冲区是字符串(在本例中为“652+346*779=” ”) lengthofnum 是相关数字的长度(在本例中 346 的长度为 3) A_ascii 是我试图将字符串“346”传输到的变量。

我有一个循环根本不起作用,而且我不知道应该使用什么寻址模式。 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:

,我收到以下错误代码:

(672) wrong parameters: MOV  A_ascii[cx],[bx]+cx

(672) probably it's an undefined var: A_ascii[cx] 

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...

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".

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

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] 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怕倦 2024-12-25 10:09:23

与(显然)流行的看法相反,您可以在 x86 上执行直接 mem->mem 移动,而无需(显式)移入/移出寄存器。由于您已经有了 CX 的长度,因此您已经开始朝着正确的方向前进:

mov si, offset A_ascii
mov di, offset B_ascii
rep movsb    ; automatically uses length from CX

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:

mov si, offset A_ascii
mov di, offset B_ascii
rep movsb    ; automatically uses length from CX
裂开嘴轻声笑有多痛 2024-12-25 10:09:23

您不能直接在两个指针之间移动。您需要将其移动到寄存器中进行临时存储:

mov dx, [bx+cx]
mov [A_ascii+cx], dx

如果您有两个要移动的内存块,通常的方法是这样的:

  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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文