Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assembler Parameter Passing Exercises. Assembler Exercise 1: Convert the following C++ code to H1 assembler. int foo(int a, char ch = ‘a’) { if ch ==

Similar presentations


Presentation on theme: "Assembler Parameter Passing Exercises. Assembler Exercise 1: Convert the following C++ code to H1 assembler. int foo(int a, char ch = ‘a’) { if ch =="— Presentation transcript:

1 Assembler Parameter Passing Exercises

2 Assembler Exercise 1: Convert the following C++ code to H1 assembler. int foo(int a, char ch = ‘a’) { if ch == ‘a’ return (int)ch; else return a;... int x = 5; int y; y = foo(x); @foo$ric: ldc ‘a’ subr 2 jnz else ldr 2 ret else: ldr 1 ret x:dw5 y:dw0 ldc ‘a’ push ld x push call @foo$ric dloc 2 st y x: 5 y: 0 ret addr ch: ‘a’ a: 5

3 Assembler Exercise 2: Convert the following C++ code to H1 assembler. int foo(int a, int*p) { int b = 5; *p = a + b; return *p... int x = 5; int y; x = foo(x,&y); @foo$ipi: ldc 5 push addr 2 push ldr 4 sti ldi dloc 1 ret x:dw5 y:dw0 ldc y push ld x push call @foo$ipi dloc 2 st xZZ heap x: 5 y: 0 p: a: 5 ret addr b: 5

4 Assembler Exercise 3: Convert the following C++ code to H1 assembler. void foo(int& a, int*p) { int b; b = a; a = *p; *p = b; return;... int x = 5; int y = 6; foo(x,&y); @foo$ripi: aloc 1 ldr 2 ; b = a ldi str 0 ldr 3 ; a = *p ldi push ldr 3 sti ldr 0 ; *p = b push ldr 4 sti dloc 1 ret x: dw5 y: dw6 main: ldc y push ldc x push call @foo$ripi dloc 2 heap x: 5 y: 6 p: a: ret addr b: -


Download ppt "Assembler Parameter Passing Exercises. Assembler Exercise 1: Convert the following C++ code to H1 assembler. int foo(int a, char ch = ‘a’) { if ch =="

Similar presentations


Ads by Google