| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2323 人关注过本帖
标题:jmp near ptr s
只看楼主 加入收藏
admin_xyz
Rank: 2
等 级:论坛游民
帖 子:195
专家分:77
注 册:2012-6-24
结帖率:97.3%
收藏
已结贴  问题点数:5 回复次数:27 
jmp near ptr s
程序代码:
assume cs:code
code segment
start:
    mov        ax, 0
    jmp        near ptr s
    db        32739 dup ('s')        ;  最多向前越过 32768 向后 32767,可是这写32769也能编译通过。求解
s:
    inc        ax
  
    mov        ax, 4c00h
    int        21h
code ends
end start
2012-09-02 20:12
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:3 
同求

梅尚程荀
马谭杨奚







                                                       
2012-09-02 21:09
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:3 
我回复一下楼主肯定会给我分的
2012-09-02 21:24
admin_xyz
Rank: 2
等 级:论坛游民
帖 子:195
专家分:77
注 册:2012-6-24
收藏
得分:0 
回复 3楼 zklhp
好歹看两眼么。。。

总有人比你努力,可怕的是比你牛的人比你还努力。
2012-09-02 21:28
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
看了 没看明白。。

near跳转就和有符号字的范围是一样的 按理这样写是错误的 但从反汇编来看是对的 能实现

难道书上错了 搞不懂了
2012-09-02 21:40
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:0 
试了下 比32768大一点可以 如果大很多就会出错 也不解~~

梅尚程荀
马谭杨奚







                                                       
2012-09-02 21:48
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
程序代码:
assume cs:code
code segment
start:
    mov        ax, 0
    jmp        near ptr s
b:
    mov        ax, 4c00h
    int        21h
    db        65000 dup ('s')        ;  最多向前越过 32768 向后 32767,可是这写32769也能编译通过。求解
s:
    inc        ax
    jmp near ptr b
    mov        ax, 4c00h
    int        21h
code ends
end start


可能编译器很聪明把它弄好了罢
2012-09-02 21:52
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
A relative offset (rel8, rel16, or rel32) is generally specified as a label in assembly
 code, but at the machine code level, it is encoded as a signed 8-, 16-, or 32-bit
 immediate value. This value is added to the value in the EIP register. (Here, the EIP
 register contains the address of the instruction following the JMP instruction). When
 using relative offsets, the opcode (for short vs. near jumps) and the operand-size
 attribute (for near relative jumps) determines the size of the target operand (8, 16,
 or 32 bits).

手册上这样说的 那么 就是编译器比较聪明的实现了

或许书上说的是错的。。。 不知道了
2012-09-02 21:55
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
Near and Short Jumps. When executing a near jump, the processor jumps to the
 address (within the current code segment) that is specified with the target operand.
 The target operand specifies either an absolute offset (that is an offset from the base
 of the code segment) or a relative offset (a signed displacement relative to the
 current value of the instruction pointer in the EIP register). A near jump to a relative
 offset of 8-bits (rel8) is referred to as a short jump. The CS register is not changed on
 near and short jumps.


2012-09-02 21:56
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
AX=0000  BX=0000  CX=FDFC  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000
DS=0B76  ES=0B76  SS=0B86  CS=0B86  IP=0003   NV UP EI PL NZ NA PO NC
0B86:0003 E9EDFD        JMP     FDF3
-t
此时我要跳到FDF3 而现在IP是3+3=6 所以我要给IP加上FD ED 从机器码看正好是这个数
AX=0000  BX=0000  CX=FDFC  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000
DS=0B76  ES=0B76  SS=0B86  CS=0B86  IP=FDF3   NV UP EI PL NZ NA PO NC
0B86:FDF3 40            INC     AX

AX=0001  BX=0000  CX=FDFC  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000
DS=0B76  ES=0B76  SS=0B86  CS=0B86  IP=FDF4   NV UP EI PL NZ NA PO NC
0B86:FDF4 E90F02        JMP     0006
-t
现在IP是FDF7 要到06得加一个数让它溢出 于是我加了020F 溢出后是06
AX=0001  BX=0000  CX=FDFC  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000
DS=0B76  ES=0B76  SS=0B86  CS=0B86  IP=0006   NV UP EI PL NZ NA PO NC
0B86:0006 B8004C        MOV     AX,4C00

看来书上说的是错的 而且指令手册也没说这回事

不过又说回来了 这个特性是编译器的么 是所有编译器都有还是只有masm有 呵呵 你们研究研究罢

好问题 有意思 加高亮了

2012-09-02 22:02
快速回复:jmp near ptr s
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018043 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved