Question

Machine Language - 1. Which of the following assembly code represents the high-level Java code below?...

Machine Language -

1. Which of the following assembly code represents the high-level Java code below?

int x;

int i = 5;

if (i < 0)

x = -1;

else

x = 1;

  1. @5

D=M

@i

M=D

@BRANCH

M;JLT

@x

M=1

@END

0;JMP

(BRANCH)

@x

M=-1

(END)

@END

0;JMP

  1. @5

D=M

@i

M=D

@BRANCH

M;JGE

@x

M=1

@END

0;JMP

(BRANCH)

@x

M=-1

(END)

@END

0;JMP

  1. @5

D=M

@i

M=D

@BRANCH

M;JLT

@x

M=1

@END

0;JMP

(BRANCH)

@x

M=-1

(END)

@END

0;JMP

  1. @x

D=M

@i

M=D

@BRANCH

M;JGE

@x

M=1

@END

0;JMP

(BRANCH)

@x

M=-1

(END)

@END

0;JMP

2. Write the assembly code that performs the following high-level Java code below:

int n = 5;

int[] arr = new int[n]; // Assume the array points to memory location 100

for (int i = 0; i < n; i++)

arr[i] = 1;

Homework Answers

Answer #1

1. No correct answer (option a and c are same here, some mistake. 2nd line code should be D=A)

@5 //A=5

D=A // D=5

@i //A=address of i

M=D //i=5

@BRANCH

M;JLT //if i<0 gto branch

@x

M=1 //x=1

@END

0;JMP //goto END

(BRANCH) //if i<5

@x

M=-1 //x=-1

(END)

@END

0;JMP //stop

Qn2)  

@5

D=A

@n

M=D              //n=5

@i

M=0              //i=0

(LOOP)

@i

D=M

@n

D=D ‐ M            

@END

D; JGE           //if (i-n)>=0 goto end

@arr

D=M

@i

A=D+M

M= 1               //arr[i]=1

@i

M=M+1               //i=i+1

@LOOP

0; JMP               //goto (LOOP)

(END)

@END

0;JMP

Using pointer concepts , arr points to memory address

@5
D=A
@n
M=D              //n=5
@100
D=A
@arr 
M=D            //arr points to  address 100
@i 
M=0              //i=0
(LOOP) 
@i 
D=M 
@n 
D=D ‐ M             
 @END 
D; JGE           //if (i-n)>=0 goto end
@arr
A=M           //address in arr stored in A
M=1     //Mem[address in arr]=Mem[100]=1 in first iteration
@arr
M=M+1  //arr=arr+1, arr values increments to 101,102 etc in each iteration.
@i 
M=M+1               //i=i+1
 @LOOP
 0; JMP               //goto (LOOP)
(END)
@END
0;JMP

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
a. Write MIPS assembly code for the following machine code. Assume that the segment is placed...
a. Write MIPS assembly code for the following machine code. Assume that the segment is placed starting at location 8000. Create labels for branch and jump instructions and indicate the 0001 0001 0010 1000 0000 0000 0000 0011 1000 1110 0001 0001 0000 0000 0000 1000 0010 0010 0010 1000 0000 0000 0000 0110 0000 1000 0000 0000 0000 0001 0000 0010 b. Translate the following C function into MIPS assembly code. int f1(int ar1[], int ar2[], int n) {...
Write the C55x assembly code for each of the following C snippet code shown below. Assume...
Write the C55x assembly code for each of the following C snippet code shown below. Assume the 8-bit values a, b, c, and d are stored in locations 0x600, 0x601, 0x602, and 0x603 respectively in the memory. Store the result x in location 0x604 and y in location 0x60C. Do not use software to generate the assembly code and comment your code. x = (a - b)3 - (c*d); for (j=0;j<=200;j++)   y = y + (a * b);
In Java programming language 11.Create the code for a for loop to print the numbers 1  through...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through 5 inclusive vertically so the output is 1 2 3 4 5 11b What is the output of the following               OUTPUT int i=3; while(int i >0) { System.out.println(i); i--; } 11c What is the output of the following               OUTPUT for(int i=3;i<10;i++) System.out.println(3*i); 11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time 11e Create the line of code...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0)    return 0; else if (n <= 2)    return 1; else {    temp = fib(n – 1);    return temp + fib(n-2); } } int main() {    int num;    cout << "Which fibonacci number? ";    cin >> num;    cout << fib(num) << endl;    return 0; } You must...
In Java 1. What will be the value of x after the following section of code...
In Java 1. What will be the value of x after the following section of code executes: int x = 3; if (x > 3)     x = x – 2; else     x = x + 2; A. 1 B.3    C.5              D.7 2. What will be the value of y after the following section of code executes: int y = 5, z = 3; if (y > 4){      z = 2;      y = y – 1;...
Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere...
Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere else. int f2(int x, int y) { int i, z = 0; for (i = x; i <= y; i++) z = z + f1(i, 5); return z; }
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)      cout...
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.    ...
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.     In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x1fff0000. Loop: sw $t1, 4($s0)        addi $t1, $t1, -1    sll $t1, $t1, 2        bne $t1, $s5, Exit    addi $s0, $s0, 4          j Loop Exit: … 2.     Find the MIPS...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your variables here .code main PROC    ; write your assembly code here    INVOKE ExitProcess,0 main...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT