C 学习汇编-所有注释,需要生成伪代码
我在阅读汇编代码方面越来越熟练,但现在我正处于一个需要将我的理解与实际构造C伪代码联系起来的阶段。作为作业的一部分,我已经注释掉了整段文章,并在下面添加了我认为会发生的事情我在这里几乎完成了这项工作。我只需要一些帮助来验证我的理解并确保我的解释是正确的。C 学习汇编-所有注释,需要生成伪代码,c,assembly,C,Assembly,我在阅读汇编代码方面越来越熟练,但现在我正处于一个需要将我的理解与实际构造C伪代码联系起来的阶段。作为作业的一部分,我已经注释掉了整段文章,并在下面添加了我认为会发生的事情我在这里几乎完成了这项工作。我只需要一些帮助来验证我的理解并确保我的解释是正确的。 804990f: ba 94 ae 04 08 mov $0x804ae94,%edx // this, on gdb is actually %d %d %d 8049914: 8b 45 08
804990f: ba 94 ae 04 08 mov $0x804ae94,%edx // this, on gdb is actually %d %d %d
8049914: 8b 45 08 mov 0x8(%ebp),%eax // function argument - parameter1 - being loaded into the eax to be considered
8049917: 8d 4d e0 lea -0x20(%ebp),%ecx // local pointer being loaded into the ecx register
804991a: 89 4c 24 10 mov %ecx,0x10(%esp) // this local pointer is now being added to the stack
804991e: 8d 4d e4 lea -0x1c(%ebp),%ecx // local pointer being loaded into the ecx register
8049921: 89 4c 24 0c mov %ecx,0xc(%esp) // this local pointer is now being added to the stack
8049925: 8d 4d e8 lea -0x18(%ebp),%ecx // local pointer being loaded into the ecx register
8049928: 89 4c 24 08 mov %ecx,0x8(%esp) // this local pointer is now being added to the stack
804992c: 89 54 24 04 mov %edx,0x4(%esp) // the three "d d d" is now also being moved to another area at the top of the stack
8049930: 89 04 24 mov %eax,(%esp) // the value of parameter one is now being treated as a pointer because address is being loaded in
8049933: e8 38 f3 ff ff call 8048c70 <sscanf@plt> // the scan function is now being called, to take in three values we passed into the array
8049938: 83 f8 03 cmp $0x3,%eax // it is comparing the parameter value which is now in the array(array[0]) to the constant 3
804993b: 74 05 je 8049942 <level_3+0x39> // if the parameter is == to 3, it jumps. so it should be like if (greater/less than)
804993d: e8 10 fa ff ff call 8049352 <call_function> // if it is not meeting these conditions, call this function
8049942: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) // move the constant 0 into a local variable x
8049949: 8b 45 e8 mov -0x18(%ebp),%eax // move array[2] into the register
804994c: 89 45 f0 mov %eax,-0x10(%ebp) // move this value into a new local variable, possible something like y = array[2];
804994f: eb 08 jmp 8049959 <level_3+0x50>
8049951: 83 45 f4 01 addl $0x1,-0xc(%ebp) // add 1 to x so x = 1
8049955: 83 45 f0 04 addl $0x4,-0x10(%ebp) // add the constant 4 to y so y += 4;
8049959: 8b 45 e4 mov -0x1c(%ebp),%eax // move array[1] into the register
804995c: 39 45 f0 cmp %eax,-0x10(%ebp) // compare array[1] to y.
804995f: 7c f0 jl 8049951 <level_3+0x48> // jump if it array[1] is less than y
8049961: 83 7d f4 03 cmpl $0x3,-0xc(%ebp) // compare this number 3 into the local variable x
8049965: 74 05 je 804996c <level_3+0x63> // jump if they are equal to one another
8049967: e8 e6 f9 ff ff call 8049352 <call_function> // if it is not meeting these conditions, call function
804996c: c7 45 f4 8c 00 00 00 movl $0x8c,-0xc(%ebp) // move the constant 140 into the local variable x
8049973: 8b 45 e4 mov -0x1c(%ebp),%eax // move array[1] into the register
8049976: 85 c0 test %eax,%eax // test this value against itself
8049978: 75 05 jne 804997f <level_3+0x76> // if it is not equal, jump
804997a: e8 d3 f9 ff ff call 8049352 <call_function> // if it is not meeting these conditions, call function
804997f: c7 45 ec 08 00 00 00 movl $0x8,-0x14(%ebp) // move the number 8 into the local variable z
8049986: eb 30 jmp 80499b8 <level_3+0xaf> // jump down and leave the function
8049988: 8b 45 e8 mov -0x18(%ebp),%eax // move arr[1] into the register
804998b: 83 e8 08 sub $0x8,%eax // subtract 8 from arr[1]
804998e: 89 45 e8 mov %eax,-0x18(%ebp) // make this is the new arr[1] value
8049991: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) // compare this number 0 to the local variable x
8049995: 75 17 jne 80499ae <level_3+0xa5> // if it is not equal, then jump down to the subtraction (subl below)
8049997: 8b 45 e0 mov -0x20(%ebp),%eax // move arr[0] into the register
804999a: c1 f8 02 sar $0x2,%eax // multiply by 4 (shifting it by 2 ^ 2)
804999d: 3b 45 ec cmp -0x14(%ebp),%eax // now move the variable z into the register
80499a0: 74 05 je 80499a7 <level_3+0x9e> // if it is equal, then jump down
80499a2: e8 ab f9 ff ff call 8049352 <call_function> // if these conditions are not met, call_function
80499a7: b8 00 00 00 00 mov $0x0,%eax // move the constant 0 into the register
80499ac: eb 1a jmp 80499c8 <level_3+0xbf> // jump down and leave the function
80499ae: 83 6d f4 07 subl $0x7,-0xc(%ebp) // from x subtract 7
80499b2: 8b 45 e4 mov -0x1c(%ebp),%eax // move array[1] into the register
80499b5: 01 45 ec add %eax,-0x14(%ebp) // now add this to the variable z. so z += array[1];
80499b8: 83 7d ec 07 cmpl $0x7,-0x14(%ebp) // compare the number 7 and the variable z
80499bc: 7f ca jg 8049988 <level_3+0x7f> // if it greater, then jump down
80499be: e8 8f f9 ff ff call 8049352 <call_function> // if these conditions are not met, call_function
80499c3: b8 00 00 00 00 mov $0x0,%eax // move the constant 0 into the register
80499c8: c9 leave // leave the function
80499c9: c3 ret // return the value
804990f:ba 94 ae 04 08 mov$0x804ae94,%edx//gdb上的这个实际上是%d%d%d
8049914:8b 45 08 mov 0x8(%ebp),%eax//函数参数-参数1-正在加载到要考虑的eax中
8049917:8d 4d e0 lea-0x20(%ebp),%ecx//正在将本地指针加载到ecx寄存器中
804991a:89 4c 24 10 mov%ecx,0x10(%esp)//此本地指针现在添加到堆栈中
804991e:8d 4d e4 lea-0x1c(%ebp),%ecx//本地指针正在加载到ecx寄存器中
8049921:89 4c 24 0c mov%ecx,0xc(%esp)//此本地指针现在添加到堆栈中
8049925:8d 4d e8 lea-0x18(%ebp),%ecx//正在将本地指针加载到ecx寄存器中
8049928:89 4c 24 08 mov%ecx,0x8(%esp)//此本地指针现在添加到堆栈中
804992c:89 54 24 04 mov%edx,0x4(%esp)//三个“d”现在也被移动到堆栈顶部的另一个区域
8049930:89 04 24 mov%eax,(%esp)//参数1的值现在被视为指针,因为正在加载地址
8049933:e8 38 f3 ff ff call 8048c70//现在正在调用scan函数,以接收传入数组的三个值
8049938:83 f8 03 cmp$0x3,%eax//它正在将数组(数组[0])中的参数值与常量3进行比较
804993b:74 05 je 8049942//如果参数为==到3,它将跳转。所以它应该是(大于/小于)
804993d:e8 10 fa ff ff调用8049352//如果不满足这些条件,则调用此函数
8049942:c7 45 f4 00 00 movl$0x0,-0xc(%ebp)//将常量0移动到局部变量x中
8049949:8b 45 e8 mov-0x18(%ebp),%eax//将数组[2]移动到寄存器中
804994c:89 45 f0 mov%eax,-0x10(%ebp)//将此值移动到一个新的局部变量中,可能类似于y=array[2];
804994f:eb 08 jmp 8049959
8049951:83 45 f4 01 addl$0x1,-0xc(%ebp)//将1添加到x,因此x=1
8049955:83 45 f0 04 addl$0x4,-0x10(%ebp)//将常量4添加到y,因此y+=4;
8049959:8b 45 e4 mov-0x1c(%ebp),%eax//将数组[1]移动到寄存器中
804995c:39 45 f0 cmp%eax,-0x10(%ebp)//将数组[1]与y进行比较。
804995f:7c f0 jl 8049951//如果它的数组[1]小于y,则跳转
8049961:83 7d f4 03 cmpl$0x3,-0xc(%ebp)//将此数字3与局部变量x进行比较
8049965:74 05 je 804996c//如果它们相等,则跳转
8049967:e8 e6 f9 ff ff调用8049352//如果不满足这些条件,则调用函数
804996c:c7 45 f4 8c 00 00 movl$0x8c,-0xc(%ebp)//将常数140移到局部变量x中
8049973:8b 45 e4 mov-0x1c(%ebp),%eax//将数组[1]移动到寄存器中
8049976:85 c0测试%eax,%eax//对照自身测试此值
8049978:75 05 jne 804997f//如果不相等,则跳转
804997a:e8 d3 f9 ff ff调用8049352//如果不满足这些条件,则调用函数
804997f:c7 45 ec 08 00 00 movl$0x8,-0x14(%ebp)//将数字8移动到局部变量z中
8049986:eb 30 jmp 80499b8//跳转并离开该函数
8049988:8b 45 e8 mov-0x18(%ebp),%eax//将arr[1]移动到寄存器中
804998b:83 e8 08 sub$0x8,%eax//从arr[1]中减去8
804998e:89 45 e8 mov%eax,-0x18(%ebp)//使这是新的arr[1]值
8049991:83 7d f4 00 cmpl$0x0,-0xc(%ebp)//将此数字0与局部变量x进行比较
8049995:75 17 jne 80499ae//如果它不相等,则跳到减法(下面的subl)
8049997:8b 45 e0 mov-0x20(%ebp),%eax//将arr[0]移动到寄存器中
804999a:c1 f8 02 sar$0x2,%eax//乘以4(将其移位2^2)
804999d:3b 45 ec cmp-0x14(%ebp),%eax//现在将变量z移动到寄存器中
80499a0:74 05 je 80499a7//如果相等,则往下跳
80499a2:e8 ab f9 ff ff调用8049352//如果不满足这些条件,则调用函数
80499a7:b8 00 mov$0x0,%eax//将常数0移动到寄存器中
80499ac:eb 1a jmp 80499c8//跳转并离开该函数
80499ae:83 6d f4 07 subl$0x7,-0xc(%ebp)//从x减去7
80499b2:8b 45 e4 mov-0x1c(%ebp),%eax//将数组[1]移动到寄存器中
80499b5:01 45 ec添加%eax,-0x14(%ebp)//现在将其添加到变量z中。so z+=数组[1];
80499b8:83 7d ec 07 cmpl$0x7,-0x14(%ebp)//比较数字7和变量z
80499bc:7f ca jg 8049988//如果它更大,则跳下
80499be:e8 8f f9 ff ff ff调用8049352//如果不满足这些条件,则调用函数
80499c3:b8 00
int *array[3];
int return_value = sscanf(param1, "%d %d %d", array[0], array[1], array[2]);
if(return_value == 3): // If there were 3 integers... see sscanf documentation
...
level_3(char* param1 ...);
int sscanf ( const char * s, const char * format, ...);
________
|params... //<--- ebp
|...
|saved caller instruction pointer (%eip) // These might be mixed up
|saved caller return location on stack (%ebp)
|locals...
|...
|space that could be used for a called functions's args //<--- esp