Friday 15 March 2013

recursion - concept beind this version of fibonacci code in assembly -


This is an alternative version of the Fibonacci code in the assembly used by my professor in this class, instead it is used as a new formula is.

  f (n-2) / 2 + f (n-1) * 2 then the sequence 1, 2, 4, 9, 20, 44, 98, 218  

I just have a few things that confuse me.

  1. What does JB and J mean?

  2. Is one and two two local variables? Do they take a different part of the equation?

  3. [ebp-4] and [ebp-8], are they the registry?

Please help me, I have really lost the concept behind this code!

This code is

this code is

  TITLE Mobonacci.586 Model FLAT, c. Mobonacci PROC; Will take N to EX; EBP Move EBP Push, ESP Mov EX, [EBP +8]; See that the eX is less than or equal to 1; CAPX, 2 JB one JJ JL1; Mobonacci calls; L1: Sub Special, 8; MOBO (N-1) * 2; Sub eX, 1 app call app call mobonachi; Mov Ebux, EX PopEx; 2 times ebx; SHL EBX, 1 Mop [EPP-4], EBX; Mobo (n-2) / 2; SubEx, 1AP Call App Call, Mobonkey MB EBX, EX POPEX; Divide the ebay from 2; Shr ebx, 1 mov [ebp-8], ebx; The sum of two numbers; Mov eax, add 0X, [EBP-4] add eX, [EPP-8]; neat pile; Mov esp, ebp jmp finished; Return 1; A: mov eax, closing 1 jmp; Return 2; Two: mov eax, 2 jmp finished; Return value in EX; End: Pop EBP ART MOBOONICIENDP End  
post-text itemprop = "text">

1) What is the JB and J mean?

They jump into the x86 instruction set. Go to jb , and j jumps if they are equal, determine whether "down" or "equals" is correct, based on recent operation which is x86 The flag affects the register. Or, in other ways, for example you compared cmp eax, ebx ( eax and ebx registers), then Jb foo value down ebx value and je foo label foo Would jump for if the values ​​were the same. Google "x86 Jump Directions" for more information

2) What is the one and two two local variables? What part of the equation do they take in the input?

No variables are labeled, which indicate the location that can jump from other places in the code. If you combine this information with the question # 1, then with the code eax with 2 ( cmp eax, 2 ) and < Code> JB jumps to a label one if less than eax 2 (its price is probably 1), and If the value of jE eax is equal to 2 , two jumps to two label. Lastly, jumps to jl1 label L1 if the value of eax is above the value is 2. Note that the next instruction label is L1 , it has no functional effect.

3) [ebp-4] and [Ebp-8] , are they the registry? Why are they elected?

In the x86 architecture the code is the base pointer register. It usually has an address in the context of [ebp-4] and [ebp-8] view the values ​​that are in the place ebp-4 And in the ebp-8 memory (the value of that address decreased from 4 to 8 and decreased to 8) why such a thing is done in this way, Google "x86 stack frame" .


No comments:

Post a Comment