如何按照这些说明使用组装中的跳转? [英] How do we use jump in assembly using these instructions?

查看:55
本文介绍了如何按照这些说明使用组装中的跳转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到装配跳动基本上是从一个位置到另一个位置.

I understand that jump in assembly is basically going from one location to another.

说我们有

804828f: 74 05            je XXXXXXX
8048291: e8 1e 00 00 00 call 80482b4 

根据这本书,我真正要做的就是在8048291上添加0x05,其结果为8048291,但是我对这里的命令感到困惑.根据这本书,操作数je是je,等于/0

According to the book, all I'm really doing is adding 0x05 to 8048291 which yields 8048291, but I am confused by what the command here is asking. According to the book, operand je is je which is equal / 0

然后我们遇到了一个复杂的问题,我真的很难缠住我的头.

Then we have a complicated one that I really am having a hard time wrapping my head around.

8048357: 72 e7                        jb XXXXXXXX
8048359: c6 05 10 a0 04 08 01 movb $0x1,0x804a010

据此,由于e7是-25的1位带符号表示, jb转到地址8048340.

According to this, since e7 is the 1bit signed representation of -25, jb goes to address 8048340.

那. . .对我毫无意义. . .完全没有.例如,如果某项已签名并且1字节的最大值不应该仅为2?其次,如果值为-25,为什么原点是8048340?如果不涉及19个,我们如何从59增至40?

That. . . Makes NO sense to me. . . AT ALL. For one, if something is signed and 1-byte shouldn't its maximum value just be 2? Secondly, if something is -25, then why is the origin 8048340? How did we go from 59 to 40 if there was no 19 involved?

我认为答案是:

我在脑子里想了一秒钟,但是要从十六进制25中得到19,我应该将16除以25,抓住它的余数9,然后将9加到10(在这种情况下1代表什么意思)吗?

I had this in my mind for a second, but to get 19 from hex 25, should I divide 16 by 25, seize its remainder which is 9 and then add 9 to 10 which is what 1 stands for in this case?

老实说,我迷失了一个带符号的单字节值.

I'm honestly lost on having a signed single byte value though.

推荐答案

在某种意义上,您可以按需要的顺序排列代码块,因此汇编中的分支很灵活.您也可以通过跳转到同一块来合并分支.要对此存档,说明必须能够向前和向后跳转.以下示例显示了向后跳转的用法.

Branching in assembly is flexible, in a sense that you can arrange the code blocks in any order you want. You can also merge the branches by jumping to the same block. To archive this the instructions must to able to jump both forward and backward. The following example shows a use of backward jumping.

073000:  bf 08 00 00 00          mov    edi, 0x8
073005:  31 c0                   xor    eax, eax
073007 <loop>:
073007:  01 f8                   add    eax, edi
073009:  83 ef 01                sub    edi, 0x1
07300c:  75 f9                   jne    073007 <loop>
07300e:

向前跳操作码后的数字为正;向后跳操作码后面的数字为负数.在二进制世界中,数字的符号由其最高位决定.在示例中,十六进制f9是二进制11111001,表示-7(有关转换方法,请参见下文).由于hex(07300e)-7是hex(073007),如果未设置,它将跳到073007是ZF(这意味着在上例中减法后edi不为零).

To jump forward the number following the Opcode is positive; to jump backward the number following the Opcode is negative. In a binary world the sign of a number is determined by its highest bit. In the example hex f9 is binary 11111001 and means -7 (see below for how to convert). Because hex(07300e) - 7 is hex(073007), it will jump to 073007 is ZF if not set (that means edi is not zero after subtraction in the above example).

在我看来,您对十六进制数字感到困惑.我将使用一些示例来说明如何将它们转换为十进制数字. Google,您可以找到更多详细信息.

It seems to me that you are confused by the hexadecimal numbers. I will use a few example to show how to convert them to decimal numbers. Google and you can find more detail.

Unsigned numbers:
0x1234 =  1*16^3 +  2*16^2 + 3*16^1 +  4 = 4660 
0x3420 =  3*16^3 +  4*16^2 + 2*16^1 +  0 = 13344 
0x0A0B =  0*16^3 + 10*16^2 + 0*16^1 + 11 = 2571   (A is 10; B is 11)
0x8000 =  8*16^3 +  0*16^2 + 0*16^1 +  0 = 37268
0xFF7A = 15*16^3 + 15*16^2 + 7*16^1 + 10 = 65402  (F is 15)

Signed numbers:
0x1234 =   ; positive because 1 is smaller than 8
0x3420 =   ; positive because 3 is smaller than 8 
0x0A0B =   ; positive because 0 is smaller than 8
0x8000 =   ; negative because 8 is NOT smaller than 8
0xFF7A =   ; negative because F (15) is NOT smaller than 8

Signed numbers:
0x1234 = 4460  ; positive numbers are calculated like unsigned number
0x3420 = 13344 ; positive numbers are calculated like unsigned number
0x0A0B = 2571  ; positive numbers are calculated like unsigned number
0x8000 = 32768 - 65536 = -32768 ; a simple way to calculate negative number
0xFF7A = 65402 - 65536 = -134 ; a simple way to calculate negative number

当第一位数字> = 8时,最高位为1,因此数字为负.

When the first digit is >= 8, the highest bit is 1 so the number is negative.

65536是2 ^ 16.

65536 is 2^16.

这篇关于如何按照这些说明使用组装中的跳转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆