1 / 4

Parameter Passing Exercises

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;

suchi
Télécharger la présentation

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. 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. Parameter Passing Exercises Assembler

  2. 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 ret addr a: 5 ch: ‘a’ Assembler

  3. 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: 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 ret addr a: 5 p: Assembler

  4. 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: - ret addr a: p: Assembler

More Related