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
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...
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 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;...
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...
LANGUAGE C The codes below reads another .c or .txt file. Then, it will read the...
LANGUAGE C The codes below reads another .c or .txt file. Then, it will read the contents of every line and store the contents into a string array. Example: .c file that is to be read: #include <stdio.h> int main(){    printf("Hello World");    return ; } _______________(END OF THE FILE)_______________ Therefore, the code will read the contents above and store the contents in every line into an array, such that.... array[0] = "#include <stdio.h>\n" array[1] = "\n" array[2] ="int...
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...
(MIPS Assembly Language): Assume the following piece of MIPS code: label1: .text 0x4000fc lui $t0, 1022...
(MIPS Assembly Language): Assume the following piece of MIPS code: label1: .text 0x4000fc lui $t0, 1022 ori $t0, $t0, 2048 srl $t1, $t0, 18 sw $t0, 101($t1) slti $t2, $t1, 5 beq $t2, $0, label3 label2:... ... label3:... a) The code modifies a word in memory at the following address (circle one): (i) 1022 (ii) 101 (iii) 5 (iv) 10220000 (v) Other (provide your own answer): _________________ b) The following value is stored in memory (circle one): (i) 0x17 (ii)...
(MIPS Assembly Language): Write the following sequence of code using *native* MIPS instructions: x = x...
(MIPS Assembly Language): Write the following sequence of code using *native* MIPS instructions: x = x - y[0] + y[1]; In memory x, y are stored beginning at 0x010000cc. Use registers $s1 for x,  and $s2 for the base address of y. Make sure your code includes all necessary declarations such that it could run in SPIM.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT