1 / 7

Practical session 7

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: DD ‘h’, ’e’, ‘l’, ‘l’, ‘o’. Little – Endian. What’s in memory? Section . bss a: RESD 1 b: RESB 12 Section .text …

isi
Download Presentation

Practical session 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 … moveax, 0x99887766 mov [a],eax … movdword[b], ‘xyz’ movebx,[b]

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

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

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

  7. global fibReg extern printf section .text str: db "n= %d; ans= %d",10,0 fibReg: push ebp movebp,esp push ebx push ecx cmpdword[ebp+8],1 jl zero ;if(n==0) je one ;if(n==1) ;;get fibReg(n-2) movebx,[ebp+8] sub ebx,2 push ebx call fibReg add esp,4 movecx,eax Recursion - example ;;get fibReg(n-1) incebx 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 movesp,ebp pop ebp ret

More Related