Question

Assume that we are using the x86-64 architecture, as mentioned in lecture 4. 2(a)  Explain the meaning...

Assume that we are using the x86-64 architecture, as mentioned in lecture 4.

2(a)  Explain the meaning of the following instruction:
               movq %rbx, (%rcx)

        State your assumptions of the content in registers and memory, before executing this instruction.
        What will happen after executing this instruction?

Answer:

[ Write answer here ]

2(b)        Convert the following code fragment (in the C language) to assembly code.

Explain steps.                                                                     [25 marks]

   long test ( long a, long b, long c ) {
       long t;

if (a>b) {

   if (a>c)

       t=a;

   else

       t=c;   

} else {

   t=b;

       }

       return t;

   }

Answer:

[ Write answer here ]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A) Here i have explained in more simplified form and also mention each and every things individually.

movq %rbx, (%rcx)

q : “quadword” refers to an eight-byte value (suffix q)

Registers %rbx, %rbp, and %r12-r15 are callee-save registers, meaning that they are saved across function calls.

Registers %rax, %rcx, %rdx, %rdi, %rsi, %rsp, and %r8-r11 are considered caller-save registers, meaning that they are not necessarily saved across function calls.

Above instruction move the eight-byte value %rbx value to the memory address of %rcx registers.

B)

test:

        push    rbp # push S Push source onto stack

        mov     rbp, rsp   # mov S, D Move source to destination

        mov     QWORD PTR [rbp-24], rdi

        mov     QWORD PTR [rbp-32], rsi

        mov     QWORD PTR [rbp-40], rdx

        mov     rax, QWORD PTR [rbp-24]

        cmp     rax, QWORD PTR [rbp-32] # cmp S2 , S1 Set condition codes according to S1 - S2

        jle     .L2 # jle / jng Label Jump if less or equal

        mov     rax, QWORD PTR [rbp-24]

        cmp     rax, QWORD PTR [rbp-40]

        jle     .L3

        mov     rax, QWORD PTR [rbp-24]

        mov     QWORD PTR [rbp-8], rax

        jmp     .L4 # jmp Jump to specified location/label

.L3:

        mov     rax, QWORD PTR [rbp-40]

        mov     QWORD PTR [rbp-8], rax

        jmp     .L4

.L2:

        mov     rax, QWORD PTR [rbp-32]

        mov     QWORD PTR [rbp-8], rax

.L4:

        mov     rax, QWORD PTR [rbp-8]

        pop     rbp

        ret # Pop return address from stack and jump there

Here i have also attached some meaning full sheet which helps you for better understanding purpose.

Hope this will works.

Add a comment
Know the answer?
Add Answer to:
Assume that we are using the x86-64 architecture, as mentioned in lecture 4. 2(a)  Explain the meaning...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 2 Assume that we are using the x86-64 architecture, as mentioned in lecture 4. 2(a)...

    Question 2 Assume that we are using the x86-64 architecture, as mentioned in lecture 4. 2(a) Explain the meaning of the following instruction: movq %rbx, (%rcx)         State your assumptions of the content in registers and memory, before executing this instruction.         What will happen after executing this instruction? (b)Convert the following code fragment (in the C language) to assembly code. Explain your steps. [25 marks] long test ( long a, long b, long c ) { long t; if...

  • Assume that we are using the x86-64 architecture Convert the following code fragment (in the C...

    Assume that we are using the x86-64 architecture Convert the following code fragment (in the C language) to assembly code. Explain your steps. [25 marks] long test ( long a, long b, long c ) { long t; if (a>b) { if (a>c) t=a; else t=c; } else { t=b; } return t; }

  • a) Write the following C function in Assembly. You must follow the System V 64-bit calling...

    a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T Syntax notation. long fibonacci (long n) { if (n == 0) return 0; else if (n == 1) return 1; else return (fibonacci (n - 1) + fibonacci (n - 2)); } b) The Windows x86-64 calling convention passes function parameters in the registers RCX, RDX, R8 and R9 and returns values on register RAX. Caller saved registers are: RAX,...

  • explain why 5. Which of the following are TRUE for the X86 call instruction? (A) Branches...

    explain why 5. Which of the following are TRUE for the X86 call instruction? (A) Branches to a specified address: (B) Pushes the instruction pointer value onto the stack; (C) Its target address may be specified in a general-purpose register; (D) Pushes flag registers onto the stack. Answer: Questions 6 - 10. True/False (Total 25 points. 5 points/question) Write T (True) or F (False) on the blank before each statement. 6. The results of code fragment sizeof(int*)=sizeof(int) depends on the...

  • (f) and (g) please f and g please letters Question 2 Indirect addressing mode in assembly language is sanilar to pointers in C. Answer the following questions: (1 point) a) How many 8-bit reg...

    (f) and (g) please f and g please letters Question 2 Indirect addressing mode in assembly language is sanilar to pointers in C. Answer the following questions: (1 point) a) How many 8-bit registers can a FSR access in the PICI8F452 MCU? b) Write the assembly language command to load the address of the variable with name: PVal into one of the FSR? (2 points) (2 points) (2 points) c) What is the meaning of: movf PREINC2, F? d) What...

  • Topics 1. MIPS instruction set architecture (ISA). 2. Performance. 3. MIPS datapath and control. Exercise 1...

    Topics 1. MIPS instruction set architecture (ISA). 2. Performance. 3. MIPS datapath and control. Exercise 1 Consider the memory and register contents shown below. Registers Ox0100 FFF8 13 ($t 5) 14 ($t6) 0x0100 FFFC 0x0101 0000 Memory 0x0000 0000 0x0001 1100 0x0A00 со00 0x1234 4321 OxBAOO OOBB 15 OXAAAA 0000 0x1111 1010 0x7FFF FFFD 0x0100 FFFO 0x0101 0008 (St7) Ox0101 0004 16 ($80) 0x0101 0008 17 ($sl) Show what changes and give the new values in hexadecimal after the following...

  • Answer all elaborately or dont even attempt. 7. (4 points) Explain why, in MARIE, the MAR...

    Answer all elaborately or dont even attempt. 7. (4 points) Explain why, in MARIE, the MAR is only 12 bits wide while the AC is 16 bits wide. Hint: Consider the difference between data and addresses. 8. (24 points) Use a few sentences to answer each of the following questions. The answers can be found in section 4.1 to 4.7 in the textbook. 1) What purpose does the datapath in a CPU serve? 2) What does the control unit in...

  • Please i need a good answer and a perfect answer.. i need unique answer use your own words. pleas...

    please i need a good answer and a perfect answer.. i need unique answer use your own words. please i need a good answer and a perfect answer.. i need unique answer use your own words. please i need a good answer and a perfect answer.. i need unique answer use your own words. don't use handwriting Q3: a) Specify the two factors used to determine the capacity of memory. Find out the memory capacity, if the number of bits...

  • third photo is problem 8 pt 2. anything would help please Problem 7 (15pts) Convert this...

    third photo is problem 8 pt 2. anything would help please Problem 7 (15pts) Convert this following pseudo-code in high level language into a piece of an assembly code (NIOS 2). In the following pseudo-code in high level language, r4, r5, r6, and r10 represent registers 4,5, 6, and 10, respectively Consider this pseudo-code in high level language: If ! (r4 >r5 or rs <r6) r10=r10+1 else r10- r10-1 This becomes the following piece in assembly code (put you answers...

  • Group Project 1 The Micro-1 Processor Simulation <Micro-1 Computer> Here's the organization of a computer equipped...

    Group Project 1 The Micro-1 Processor Simulation <Micro-1 Computer> Here's the organization of a computer equipped with a Micro-1 processor Memory contains an array of integer cells: int cell[] = new int[CAP]; where CAP is the capacity of memory. Initially this is set to 256. Internally, the Micro-1 processor is equipped with eight 32-bit data/address registers and two 32 bit control registers: PC, the program counter, contains the address of the next instruction to execute. IR, the instruction register, contains...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT