Presentation is loading. Please wait.

Presentation is loading. Please wait.

Practical session 7 review. Little – Endian What’s in memory? Section.rodata a: DB ‘hello’, 0x20, ’world’, 10, 0 b: DW ‘hello’, 0x20, ’world’, 10, 0 c:

Similar presentations


Presentation on theme: "Practical session 7 review. Little – Endian What’s in memory? Section.rodata a: DB ‘hello’, 0x20, ’world’, 10, 0 b: DW ‘hello’, 0x20, ’world’, 10, 0 c:"— Presentation transcript:

1 Practical session 7 review

2 Little – Endian What’s in memory? Section.rodata a: DB ‘hello’, 0x20, ’world’, 10, 0 b: DW ‘hello’, 0x20, ’world’, 10, 0 c: DD ‘h’, ’e’, ‘l’, ‘l’, ‘o’

3 Little – Endian What’s in memory? Section.bss a: RESD 1 b: RESB 12 Section.text … mov eax, 0x99887766 mov [a],eax … mov dword[b], ‘xyz’ mov ebx,[b]

4 #include extern void fib(int n,int* arr); int main(int argc,char* argv[]){ //gets a number 'n' from input, calculate & print fib[1..n] int n= atoi(argv[1]); int i=0; int ans[n]; fib(n,ans); for(i=0; i< n; i++) printf("%d ",ans[i]); printf("\n"); return 0; } gets a number n>0 as argument, calculate & print fib[0..n-1] arrays - example

5 global fib section.text fib: push ebp mov ebp,esp pusha ;int arr[] mov esi,[ebp+12] ;int n is assumed to be > 1 mov ecx,[ebp+8] mov dword[esi],0 ;fib(0) = 0 mov dword[esi+4],1 ;fib(1) = 1 sub ecx,2 jz end l: mov eax,[esi] add eax,[esi+4] mov [esi+8],eax add esi,4 loop l end: popa pop ebp ret

6 #include extern int fibReg(int n); int main(int argc,char* argv[]){ int n= atoi(argv[1]); int ans= fibReg(n); printf("%d \n",ans); return 0; } gets a number n>=0 as argument, calculate & print fib(n) recursively Recursion - example

7 ;;get fibReg(n-1) inc ebx push ebx call fibReg add esp,4 add eax,ecx jmp end zero: mov eax,0 jmp end one: mov eax,1 end: pop ecx pop ebx mov esp,ebp pop ebp ret Recursion - example global fibReg extern printf section.text str: db "n= %d; ans= %d",10,0 fibReg: push ebp mov ebp,esp push ebx push ecx cmp dword[ebp+8],1 jl zero;if(n==0) je one;if(n==1) ;;get fibReg(n-2) mov ebx,[ebp+8] sub ebx,2 push ebx call fibReg add esp,4 mov ecx,eax


Download ppt "Practical session 7 review. Little – Endian What’s in memory? Section.rodata a: DB ‘hello’, 0x20, ’world’, 10, 0 b: DW ‘hello’, 0x20, ’world’, 10, 0 c:"

Similar presentations


Ads by Google