CODING :
The given expression is
{\color{Red} A = (B - (C + D)) * (E + F)}
Assume R1, R2 are registers. M[ ] is any memory location.
The instructions ADD, SUB, MUL are used for addition, subtraction and multiplication respectively.
An n-address machine will specify n operand addresses in the instruction. So, a 3-address machine has instructions like ADD R1,A,B where R1 = M[A] + M[B]. The instruction adds the content at memory location A and B and places the result in the register R1.
3-address instruction for given expression:
ADD R1, C, D # R1 = M[C] + M[D]
SUB R1, B, R1 # R1 = M[B] - R1
ADD R2, E, F # R2 = M[E] + M[F]
MUL A, R1, R2 # M[A] = R1 * R2
2-address instruction for given expression:
Here, two addresses are specified in the instructions and MOV instruction is used for data movement.
MOV R1, C # R1 = M[C]
ADD R1, D # R1 = R1 + M[D]
MOV R2, B # R2 = M[B]
SUB R2, R1 # R2 = R2 - R1
MOV R1, E # R1 = M[E]
ADD R1, F # R1 = R1 + M[F]
MUL R1, R2 # R1 = R1 * R2
MOV A, R1 # M[A] = R1
1-address instruction for given expression:
1-address machine uses an accumulator AC to hold one operand. One operand is in accumulator and other is in the register or memory location. There is no need to explicitly specify the accumulator as CPU already knows it.
LOAD and STORE instructions are used for data movement.
LOAD C # AC = M[C]
ADD D # AC = AC + M[D]
STORE T # M[T] = AC
LOAD B # AC = M[B]
SUB T # AC = AC - M[T]
STORE T # M[T] = AC
LOAD E # AC = M[E]
ADD F # AC = AC + M[F]
MUL T # AC = AC * M[T]
STORE A # M[A] = AC
0-address instruction for given expression:
0- address machine uses a stack to store both source operands and destination operands. PUSH and POP instructions are used for data movement. The expression is converted to reverse Polish notation.
TOP means the top of the stack.
Reverse Polish Notation - B C D + - E F + *
PUSH B # TOP = B
PUSH C # TOP = C
PUSH D # TOP = D
ADD # TOP = C + D
SUB # TOP = B - (C + D)
PUSH E # TOP = E
PUSH F # TOP = F
ADD # TOP = E + F
MUL # TOP = (B - (C + D)) * (E + F)
POP A # M[A] = TOP
Write the code to implement the expression A (((B C)/D) *(E F) *G) on 3-, 2-, 1-, and 0- address ...
Word Bank: a) python b) computer science c) algorithm d) program e) interpreter f) compiler g) syntax h) semantics i) value J) variable k) operator l) operand m) expression n) statement o) input p)output q)call r) arguments s) library t) bug u) variable scope v) local variable w)global variable x) variable lifetime y) relational operators z) logical operators 1) Compares operands and results in a bool: 2) The duration of a variable's existence: 3) A list of instructions to solve...
3. Assume that the variables £, g, i are assigned to registers $so, $s1, 5s2 respectively. Assume that the base address of arrays A, B, C are in registers Ss6, Ss7, Ss8 Write down MIPS instructions that implement the following C statement: (a) f = g- A(B [C[B+1]]]; 3. Assume that the variables £, g, i are assigned to registers $so, $s1, 5s2 respectively. Assume that the base address of arrays A, B, C are in registers Ss6, Ss7, Ss8...
6. In this problem, you are to implement a 3-bit ALU which performs the following 4 operations on 3-bit operands A and B and generates the result F and the overflow status OV: (a) op(1:0) 00: A AND B (b) op(1:0)#: 01 : A OR B. (c)op(1:0),# 10: A +13. (d) 01, (1 : 0) t# 11 : A B, For arithmetic operations, assume that A and B are two's complement integers, e.g.. 0112 3, n and 1002 ten The...
1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume f, g, h correspond to $80, $s1, and $s2, respectively. f=g+(h-5) 2. (15 pts) For the following pseudo-MIPS assembly instructions, what is the corresponding C code? add f, g, h add f,i, f 3. (30 pts) Provide the instruction type, assembly language instruction, and binary representation of the instruction described by the following MIPS fields: a. op = 0, rs = 18, rt=9, rd...
1. Consider the code sequence: C= A + B D= A-E F= C+ D Assume the values A, B, C, D, E, and F reside in memory. For each Architecture I. Accumulator Architecture II. Memory- Register Architecture III. Register-Register Architecture write the code assuming the instruction codes (opcode) are 8 bits, memory addresses are 32 bits, and register addresses are 6 bits and CPU has 64 Registers; and create a table which specifies: – The execution sequence – The variables...
2. Implement the functions: F(a,b,c,d) - abc + d and G a' using two 3-input 2-output lookup tables. Assume the two lookup tables are connected in the manner as shown below: 8x2 Mem em. 1 dl d0 dl do Cu
(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...
please code using risc-v language and make it as simple as possible Problem 1: (20 marks) Part 1: (15 points) Compile the RISC-V assembly code for the following C code. Assume that n and k are passed in x3 and x4 respectively. Values n and k are initialized to 14 and 14. Assume that result returned in register fl and that double precision numbers are used. After you are done store the result in address: 12(x3). Are you allowed to?...
1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...
(ii) f = g - A[C[16) + B[321) (iii) A[i] 4B[8i-811 + 4C[32i+321 Problem 2. Consider the following code (again, assume a 64-bit machine) ld x6, 0 (x7) sd x6, 8(x7) Assume that the register x7 contains the address 0x1000000000000000 and the data at address is 0x112233445566778899 AABBCCDDEEFF. a. What value is stored in 0x100000000000000F on a bigendian machine? b. What value is stored in 0x100000000000000F on a littleendian machine? Problem 1. Write down the RISC V code for the...