Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 返回时出现语法问题_Assembly - Fatal编程技术网

Assembly 返回时出现语法问题

Assembly 返回时出现语法问题,assembly,Assembly,我是个新手,所以对装配不太了解。我使用的是MASM611和DosBox 0.74。目前,我正在编写一个代码,其中我必须从另一个标签返回到上一个标签。我也不确定'ret'的语法。此外,在调试过程中,“ret”处也会出现问题 代码如下所示: label1: cmp bl,bh je loop jmp display loop: inc count ret 我想让我的程序回到label1中它跳转到“循环”的那个点。基本上,代码要求字母表,当我给它字母表时,程序进入永久循环(很可能,因为它不工作)。

我是个新手,所以对装配不太了解。我使用的是MASM611和DosBox 0.74。目前,我正在编写一个代码,其中我必须从另一个标签返回到上一个标签。我也不确定'ret'的语法。此外,在调试过程中,“ret”处也会出现问题

代码如下所示:

label1:
cmp bl,bh
je loop
jmp display

loop:
inc count
ret

我想让我的程序回到label1中它跳转到“循环”的那个点。基本上,代码要求字母表,当我给它字母表时,程序进入永久循环(很可能,因为它不工作)。调试后,它可以正常工作到'ret',但随后会失去跟踪或其他功能。

您不能将
ret
与跳转结合使用,以在跳转位置后返回。原因是跳转指令不在堆栈上存储返回地址,
ret
需要返回地址才能工作

使用另一个跳转:

    je loop
back:                -- see jmp below which jumps back here
    jmp display

loop:
    inc count
    jmp back
或者使用
call
指令调用子程序:

    jne no_call      -- skip the call if condition is not met
    call subprog
no_call:             -- 'ret' will return back here, as well as the jne above
    jmp display

subprog:
    inc count
    ret

请注意,在特定的汇编程序中,可能需要更复杂的语法来声明子程序。

不能将
ret
与跳转结合使用,以在跳转位置后返回。原因是跳转指令不在堆栈上存储返回地址,
ret
需要返回地址才能工作

使用另一个跳转:

    je loop
back:                -- see jmp below which jumps back here
    jmp display

loop:
    inc count
    jmp back
或者使用
call
指令调用子程序:

    jne no_call      -- skip the call if condition is not met
    call subprog
no_call:             -- 'ret' will return back here, as well as the jne above
    jmp display

subprog:
    inc count
    ret

请注意,在您的特定汇编程序中,可能需要更复杂的语法来声明子程序。

JCC/JMP不会为其推送返回地址。正如昂德雷解释的那样,你需要打电话。(并且没有条件调用指令)

一种更有效的方法来解决这一混乱的分支问题

label1:        ;; jump to display after count += (bl == bh)
    cmp   bl,bh
    jne   display        ; jump straight there if there's no need to increment
    inc   count          ; preferably keep this in a register; Try to avoid memory for things you modify in a loop.
    jmp   display

初学者代码的指令和分支比应该的多得多是很正常的。除了运行速度更快之外,简化分支通常会使人类更容易理解/阅读/遵循,这绝对是件好事。

JCC/JMP不会为用户推送返回地址。正如昂德雷解释的那样,你需要打电话。(并且没有条件调用指令)

一种更有效的方法来解决这一混乱的分支问题

label1:        ;; jump to display after count += (bl == bh)
    cmp   bl,bh
    jne   display        ; jump straight there if there's no need to increment
    inc   count          ; preferably keep this in a register; Try to avoid memory for things you modify in a loop.
    jmp   display

初学者代码的指令和分支比应该的多得多是很正常的。除了运行速度更快之外,简化分支通常会使人类更容易理解/阅读/遵循,这绝对是件好事。

您需要更具体地说明您的问题(例如:发生了什么问题?是错误吗?如果是,那么会发生什么?(消息等)。另外,当执行
ret
时,您预计会发生什么情况?
ret
在调用函数的指令之后的下一条指令继续执行。您需要更具体地说明您的问题(例如:发生了什么问题?是错误吗?如果是,则会发生什么?(消息等)。另外,当执行
ret
时,您预计会发生什么情况?
ret
在调用函数的指令之后的下一条指令继续执行。