Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tutorial 6 solutions
MIỄN PHÍ
Số trang
6
Kích thước
87.0 KB
Định dạng
PDF
Lượt xem
1684

Tutorial 6 solutions

Nội dung xem thử

Mô tả chi tiết

Week 13 Solutions

Code Generation

1. Write Jasmin code for the following MC program:

int a,b[3];

float c[4],d;

int foo(boolean e,int f[]) {

if (e && (f[1]==0))

a = 1;

else

b[1] = a = 2;

return a;

}

int main() {

int e[3],f;

for (f = 1; f < 3; f = f +1)

e[f] = 0;

foo(true,e);

repeat

b[0] = a + b[0];

until (b[0] > 10);

return 0;

}

Change the above MC program to Java program:

public class Cout {

static int a;

static int b[] = new int[3];

static float c[] = new float[4];

static float d;

static int foo(boolean e,int f[]) {

if (e && (f[1] == 0))

a = 1;

else

b[1] = a = 2;

return a;

}

void main(String[] args) {

int e[] = new int[3];

int f;

for (f = 1; f < 3; f = f +1)

e[f] = 0;

foo(true,e);

do

b[0] = a + b[0];

while (!(b[0] > 10));

return ;

}

}

Compile the above Java program:

javac –g Cout.java

Translate to jasmin code by running JavaToJasmin.bat

.source Cout.java

.class public Cout

.super java/lang/Object

.field static a I

.field static b [I

.field static c [F

.field static d F

.method public <init>()V

.limit stack 1

.limit locals 1

.var 0 is this LCout; from

Label0 to Label1

Label0:

.line 1

aload_0

invokespecial

java/lang/Object/<init>()V

Label1:

return

.end method

.method static foo(Z[I)I

.limit stack 4

.limit locals 2

.var 0 is e Z from Label3 to

Label4

.var 1 is f [I from Label3 to

Label4

Label3:

.line 7

iload_0

ifeq Label0

aload_1

Tải ngay đi em, còn do dự, trời tối mất!