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 (a>b) {
if (a>c)
t=a;
else
t=c;
} else {
t=b;
}
return t;
}
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) here i have explained all the instruction in the program i also mentioned the Registers meaning in the above answer. I have tried to be explain in more simplified way.
test:
push rbp # push S Push source onto stack
mov rbp, rsp # mov s d move the source value to destination register.
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
.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 # ret Pop return address from stack and jump there
I have cover all the command usage and also there functionality
Question 2 Assume that we are using the x86-64 architecture, as mentioned in lecture 4. 2(a)...
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)...
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 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,...
a) Write the following C function in Assembly. You must follow
the System V 64-bit calling convention and use AT&T Syntax
notation. Note: You cannot change the algorithm in any way so your
assembly function must still be recursive. (20 points) long Catalan(long n) { long sum
= 0; if (n == 0) return 1; for (int i = 0; i < n; i++) { sum +=
Catalan(i) * Catalan(n - i - 1); } return sum; } b) The...
5. Assume DS-1000, CS- 800, Ax-3412H, and BX-0200H. For the following x86 assembly code: MOV [BX +1000H], AX a) Translate the assembly code to machine code (in Hex). The opcode of MOV instruction is 100010. b) Show the values of AX, BX, and new values in memory, if there are, in the following figure c) (10 points) AFTER executing the instruction. (5 points) What is the memory address accessed by the instruction, assuming real mode operation? Show it in the...
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...
Section B - ARM Assembly Language (25 marks) An ARM instruction set summary is provided at the end of this paper 1. (5 marks) Consider the following assembly instruction STMFD r13!, (r5-6} Before executing this instruction, registers hold the following values: Register Value Register r9 Value r4 0x00400040 0x00000000 r5 r10 0x11223344 0x00800080 r6 0x55667788 r11 0x10001000 r7 0x99aabbcc r12 0x20002000 r8 exddeeff00 r13 ex40004000 What memory locations are affected after executing the above instruction? In a table, with a...
(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 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...
Consider the following assembly code. 1. 1, LOAD R, #1 2, LOADS, #1 3, LOAD T, #(k-3) 4. ADD AC, R, S 5. LOAD R, S 6. LOAD S, AC 8. BRP 4, T 9. STOR AC, M where R, S, T, AC are is addressing and BRP stands for "branch if positive". sters, M is a memory location, # indicates immediate (a) Explain what this code computes (assuming that k is a natural number greater than two). (6 marks)...