b Consider a CPU with four general purpose registers (RO, RI, R2 and R3) and the
ID: 3712776 • Letter: B
Question
b Consider a CPU with four general purpose registers (RO, RI, R2 and R3) and the following machine instructions: Opcode Instruction 0000 STOP 0001 LOAD Rm, Addr 0010 STORE Rm, Add?r 0011 LOAD Rm, [Rn 0100 STORE Rm, [Rn] 0101 INC Rm 0110 DEC Rm 0111 JGT Rm, Rn, Addr If Rm>Rn, PC (program count)- Addr Action Stop program execution Rm = Memory [Addr] Memory [Addr] = Rm Rn Memory [Rn] Memory [Rn] Rm Rm Rm+1 Rm Rm-1 Let a set of n variables A[0), A[I],..A[n-1] be stored at consecutive memory locations with addresses starting from 0, 1,2,... to n-1. Each memory location can store one single variable or instruction. Note that n is a positive integer, which can be even or odd. Write a pseudo-code program to re-arrange the locations of these variables such that A [0], A [1], .. ., A [n-1] are now stored at memory addresses starting from n- 1, n-2, n-3, 2, 1 to 0, respectively. Using the above machine instructions, write the corresponding assembly program to perform the task. It is assumed that the value of n is pre-stored at some memory location. Define necessary constants and temporary variables, and provide their memory locations in hexadecimals. Also specify the memory locations of your assembly instructions.Explanation / Answer
ANS:-
PROGRAM:-
Pseudo code:
1.start
2.read B
3.read C
4.until C=0
Add B to previous value of B
5.store the result in A
6.stop?
Assembly instructions:
LOAD R0,B
LOAD R1,C
LOOP:IFZER R3,AFTER
ADD R2,B
SUB R3,C
GOTO LOOP
AFTER:STORE R2,A
STOP
Two constants LOOP and AFTER
For example:
Memory address of B is [0001]
Memory address of C is [0005]
Memory address of LOOP is [0010]
Memory address of AFTER is [0014]
Memory address of A is [0019]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.