装配中的非法指令

发布于 2024-08-29 05:03:23 字数 745 浏览 8 评论 0原文

我真的不明白为什么这个简单的代码在第一次尝试时工作得很好,但是当 将其放入程序中时会出现错误:

NTVDM CPU 遇到非法指令 CS:db22 IP:4de4 OP:f0 ff ff ff ff

第一个代码段工作得很好:

.model small
.stack 100h
.code

start:
  mov ax,@data
  mov ds,ax
  mov es,ax

   MOV AH,02H    ;sets cursor up            
   MOV BH,00H
   MOV DH,02
   MOV DL,00
   INT 10H

EXIT:

MOV AH,4CH
INT 21H
END

但是这会生成一个错误:

.model small
.stack 100h
.code

start:
  mov ax,@data
  mov ds,ax
  mov es,ax

  call set_cursor

  PROC set_cursor near

  MOV AH,02H    ;sets cursor up             
  MOV BH,00H
  MOV DH,02
  MOV DL,00
  INT 10H
 RET
 set_cursor ENDP

EXIT:

  MOV AH,4CH
  INT 21H
  END

注意:Windows 配置没有任何问题。我已经尝试了很多工作正常的示例代码

谢谢

I really do not understand why this simple code works fine in the first attempt but when
putting it in a procedure an error shows:

NTVDM CPU has encountered an illegal instruction
CS:db22 IP:4de4 OP:f0 ff ff ff ff

The first code segment works just fine:

.model small
.stack 100h
.code

start:
  mov ax,@data
  mov ds,ax
  mov es,ax

   MOV AH,02H    ;sets cursor up            
   MOV BH,00H
   MOV DH,02
   MOV DL,00
   INT 10H

EXIT:

MOV AH,4CH
INT 21H
END

However This generates an error:

.model small
.stack 100h
.code

start:
  mov ax,@data
  mov ds,ax
  mov es,ax

  call set_cursor

  PROC set_cursor near

  MOV AH,02H    ;sets cursor up             
  MOV BH,00H
  MOV DH,02
  MOV DL,00
  INT 10H
 RET
 set_cursor ENDP

EXIT:

  MOV AH,4CH
  INT 21H
  END

Note: Nothing is wrong with windows config. I have tried many sample codes that work fine

Thanks

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

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

发布评论

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

评论(2

写下不归期 2024-09-05 05:03:23

您遗漏了 JMP:

call set_cursor
jmp EXIT ; <== you forgot this part

PROC set_cursor near

发生的情况是,在调用 set_cursor 之后,您将进入过程并再次执行它,然后当您点击 >ret 它弹出堆栈,然后你跳转到,好吧,谁知道呢?

编辑:正如其他人指出的那样,最好将 PROC 放在主代码结束之后,而不是将其放在中间并在其周围跳转。但你可能已经明白了:)

You left out a JMP:

call set_cursor
jmp EXIT ; <== you forgot this part

PROC set_cursor near

What's happening is that after call set_cursor, you're then falling through to the proc and and executing it again, then when you hit the ret it pops the stack and you jump to, well, who knows?

Edit: As someone else pointed out, you're better off putting your PROC after your main code ends, instead of sticking it in the middle and jumping around it. But you've probably figured that out already :)

戏蝶舞 2024-09-05 05:03:23

您应该将程序的代码移到退出程序的部分之后(或遵循egrunin 的建议)。

段错误的原因是过程中的代码在您第一次调用它后再次执行。在第二次执行期间,代码在 RET 处崩溃,因为堆栈上没有有效的返回地址。

You should move the code of the procedure after the part where you exit the program (or follow egrunin's advice).

The reason for your segfault is that the code in the procedure is executed again after you first call it. During the second execution the code crashes on RET because there is no valid return address on the stack.

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