Parameter Passing Exercises

1 / 4

# Parameter Passing Exercises - PowerPoint PPT Presentation

Parameter Passing Exercises. Exercise 1:. @foo\$ric: ldc ‘a’ subr 2 jnz else ldr 2 ret else: ldr 1 ret. Convert the following C++ code to H1 assembler. int foo(int a, char ch = ‘a’) { if ch == ‘a’ return (int)ch;

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' Parameter Passing Exercises' - suchi

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Parameter Passing Exercises

Assembler

Exercise 1:

@foo\$ric:

ldc ‘a’

subr 2

jnz else

ldr 2

ret

else:

ldr 1

ret

• Convert the followingC++ code to H1assembler.

int foo(int a, char ch = ‘a’) {

if ch == ‘a’

return (int)ch;

else

return a;

. . .

int x = 5;

int y;

y = foo(x);

x: dw 5

y: dw 0

ldc ‘a’

push

ld x

push

call @foo\$ric

dloc 2

st y

x: 5

y: 0

a: 5

ch: ‘a’

Assembler

Exercise 2:

@foo\$ipi:

ldc 5

push

push

ldr 4

sti

ldi

dloc 1

ret

• Convert the followingC++ code to H1assembler.

int foo(int a, int*p) {

int b = 5;

*p = a + b;

return *p

. . .

int x = 5;

int y;

x = foo(x,&y);

x: dw 5

y: dw 0

ldc y

push

ld x

push

call @foo\$ipi

dloc 2

st xZZ

x: 5

y: 0

heap

b: 5

a: 5

p:

Assembler

Exercise 3:

@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

• Convert the followingC++ code to H1assembler.

void foo(int& a, int*p) {

int b;

b = a;

a = *p;

*p = b;

return;

. . .

int x = 5;

int y = 6;

foo(x,&y);

x: 5

y: 6

x: dw 5

y: dw 6

main:

ldc y

push

ldc x

push

call @foo\$ripi

dloc 2

heap

b: -