Question

In: Computer Science

Show the machine code corresponding to the Y86 version of the following code. Assume that the...

Show the machine code corresponding to the Y86 version of the following code. Assume that the code starts at location 0x050. For each statement, list address: code bytes.

int sumInts ( long int n) { /* Add the integers from 1..n. */ long int i; long int sum = 0; for ( i = 1; i <= n; i++ ) { sum += i; } return sum; }

Solutions

Expert Solution

Assembly code :

sumInts:
1       irmovl $0,eax           # sum = 0
2       irmovl $1,ebx           # i = 1
Loop:
3       rrmovl %esp,%edx       # %esp = n; counter(%edx) = n ; to compare with i for looping
4       addl %ebx,%eax           # sum = sum + i
5       irmovl $1,%ecx
6       addl %ecx,%ebx           # i = i+1
7       subl %ebx,%edx           # counter = counter - i ; it becomes negative when i = n+1
8       jl Loop                   # if counter >= 0, goto Loop
9       ret                       # return when counter < 0



Corresponding machine code by line numbers as mentioned above assuming code starts at 0x050 :


1 0x050   : 30F000000000
2 0x056 : 30F100000001
3 0x05C : 2042
4 0x05F : 6010
5 0x061 : 30F200000001
6 0x067 : 6021
7 0x069 : 6113
8 0x06B : 720000005C
9 0x070 : 90


Related Solutions

Question: In the following MIPS assembly code, translate all the instructions to their corresponding machine code...
Question: 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 0x2fff0004. Loop: lw $t0, 4($s0)             addi $t1, $t1, -15             sll $t1, $t1, 2             beq $t1, $s1, Exit             addi $s0, $s0, 4             j Loop Exit: …
First, draw the state machine for the following program. Then write the corresponding Verilog behavioral code....
First, draw the state machine for the following program. Then write the corresponding Verilog behavioral code. Input: X - 1 bit number Output: Z - 1 bit number Clock: clk (State will change at positive edge of the clock) Output will be equal to one if Xn-2 Xn-1 Xn = 011 or Xn-2 Xn-1 Xn = 101
Write assembly code for the following machine code. Assume that the segment is placed starting at...
Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual memory addresses represented by such labels. 0010 1010 0000 1000 0000 0000 0000 1010 0001 0001 0000 0000 0000 0000 0000 0010 0000 0010 0001 0001 1000 0000 0010 0000 0000 1000 0000 0000 0100 1110 0010 0101 0000 0010 0001 0010 1000 0000 0010 0000
a. Write machine code for the following assembly code. Assume that the segment is placed starting...
a. Write machine code for the following assembly code. Assume that the segment is placed starting at location 80000. Use decimal numbers to represent each instruction. loop:         beq $s3, $s1, endwhile                  add $t0, $s3, $s4                  lw $t1, 0($t0)                  add $s0, $s0, $t1                  addi $s3, $s3, 4                  j loop endwhile: b. Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual...
1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C...
1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C variables a, b, and c, have already been placed in registers x10, x11, and x12 respectively. Use a minimal number of RISC-V assembly instructions. a = b + (c − 2); 2. Write a single C statement that corresponds to the two RISC-V assembly instructions below. add e, f, g add e, h, e 3. Assume that registers x5 and x6 hold the values...
Show the output of the following code. Assume the node is in the usual info-link form...
Show the output of the following code. Assume the node is in the usual info-link form with info of the type int. Also, list and ptr are reference variables of the type Node. list = new Node( ); list.info = 88; ptr = new Node( ); ptr.info = 41; ptr.link = null; list.link = ptr; ptr = new Node( ); ptr.info = 99; ptr.link = list; list = ptr; ptr = new Node( ); ptr.info = 19; ptr.link = list.link;...
Assume that we are executing the following code on a 32-bit machine using two’s complement arithmetic...
Assume that we are executing the following code on a 32-bit machine using two’s complement arithmetic for signed integers. Which of the following will be printed when the following code is executed (circle those printed, and show work; e.g., how the values are stored): #include <stdio.h> int main() { char x = 0xF;                // x = ________ char y = -1;                 // y = ________ unsigned char z = 0xFF;      // z = 11111111        if (x<z)     printf("performed unsigned compare,...
Code the FSM in C++, and show that the program works. Construct a Finite State Machine...
Code the FSM in C++, and show that the program works. Construct a Finite State Machine that models an old-fashioned soda machine that accepts nickels, dimes, and quarters. The soda machine accepts change until 35 cents have been put in. It gives change back for any amount greater than 35 cents. Then the customer can push buttons to receive either a cola, a root beer, or a ginger ale.
Q)Determine the complexity of the following code chunks. Show all calculations. (Assume that f() has complexity...
Q)Determine the complexity of the following code chunks. Show all calculations. (Assume that f() has complexity O(1)). A)for(i=0; i<n; i++) m += i; B) for(i=0; i<n; i++)                   for(j=0; j<n; j++)                             sum[i] += entry[i][j]; C) for(i=0; i<n; i++)                   for(j=0; j<i; j++)                             m += j; D) i= 1; while(i< n) { tot += i; i= i* 2;} E) i= n; while(i> 0) { tot += i; i= i/ 2; } F) for(i=0; i<n; i++)                  for(j=0; j<n; j++)...
For the following u(x, y), show that it is harmonic and then find a corresponding v(x,...
For the following u(x, y), show that it is harmonic and then find a corresponding v(x, y) such that f(z)=u+iv is analytic. u(x, y)=(x^2-y^2) cos(y)e^x-2xysin(y)ex
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT