Parameter passing exercises
This presentation is the property of its rightful owner.
Sponsored Links
1 / 4

Parameter Passing Exercises PowerPoint PPT Presentation


  • 39 Views
  • Uploaded on
  • Presentation posted in: General

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;

Download Presentation

Parameter Passing Exercises

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

Parameter Passing Exercises

Assembler


Exercise 1

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:dw5

y:dw0

ldc ‘a’

push

ld x

push

call @foo$ric

dloc 2

st y

x: 5

y: 0

ret addr

a: 5

ch: ‘a’

Assembler


Exercise 2

Exercise 2:

@foo$ipi:

ldc 5

push

addr 2

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:dw5

y:dw0

ldc y

push

ld x

push

call @foo$ipi

dloc 2

st xZZ

x: 5

y: 0

heap

b: 5

ret addr

a: 5

p:

Assembler


Exercise 3

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: dw5

y: dw6

main:

ldc y

push

ldc x

push

call @foo$ripi

dloc 2

heap

b: -

ret addr

a:

p:

Assembler


  • Login