. : : Assembly Language : : .  |  首页  |  我提出的问题  |  我参与的问题  |  我的收藏  |  消息中心   |  游客  登录  | 
提问 | 未解决 | 已解决 | 精华区 | 搜索 |
  《汇编语言》论坛 ->转移指令的原理
主题 : :  实验8        这个程序可以正确返回吗?        运行后为什么是这种结果?       ■■■详解  [待解决] 回复[ 10次 ]   点击[ 1639次 ]  
stop1204
[帖 主] [ 发表时间:2013-05-16 00:21 ] 
荣誉值:424
信誉值:0
注册日期:2013-04-08 10:06
assume cs:codesg
codesg segment
        mov ax,4c00h        ;ip=0
        int 21h                ;ip=3
start:        mov ax,0        ;ip=5        ;程序入口
s:        nop                ;ip=8                ;经过运行以下代码,此处机器码 90 变成 EBF6
        nop                ;ip=9
        mov di,offset s        ;ip=10        di=8H
        mov si,offset s2;ip=13        si=20H
        mov ax,cs:[si]        ;ip=16        ax = cs:20 传送了指令[jmp short s1]的机器码EBF6 到AX
        mov cs:[di],ax        ;ip=19        cs:8 = ax   copy了数据 EBF6 而不是指令
s0:        jmp short s        ;ip=22        跳转到cs:8执行 jmp short s1
s1:        mov ax,0        ;ip=24
        int 21h                ;ip=27
        mov ax,0        ;ip=29
s2:        jmp short s1        ;ip=32d=20H  机器码 EBF6 ;12-22 = -10 补码 11110110B  246D  F6H
        nop                ;ip=34
codesg ends
end start
可以正确返回,运行结果:
执行ip=16 → ax = [jmp short s1] ip=19→cs:8 = [jmp short s1] ip=22→跳转到cs:8执行
(机器码跟原来的 EBF6 ,F6H=-10B) 向后移动10个字节 ip=0 → mov ax,4c00h int 21h
guochl
[第7楼] [ 回复时间:2016-03-20 22:09 ] 
荣誉值:0
信誉值:0
注册日期:2016-02-29 13:00
code segment
assume cs:code,ds:data,ss:stack

        mov ah,4ch
        int 21h
start:
        mov ax,0
        nop             ;此处增加一个NOP就可以正确返回了。
s:
        nop        ;f6
        nop        ;eb
        
        mov di,offset s        ;di=0007
        mov si,offset s2        ;si=001f
        mov ax,cs:[si]        ;ax=f6eb
        mov cs:[di],ax        ;[di]=
s0:
        jmp short s
s1:
        mov ax,0
        int 21h
        mov ax,0
s2:
        jmp short s1
        nop
        
code ends
end start
需要登录后才能回帖 -->> 请单击此处登录
    Copyright © 2006-2024   ASMEDU.NET  All Rights Reserved