0% found this document useful (0 votes)
30 views

3-Instruction Set Architecture

Uploaded by

khoipn.23bi14228
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

3-Instruction Set Architecture

Uploaded by

khoipn.23bi14228
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Given the following program.

.text
.globl main
main:
li $a0, 5
jal function
move $a0, $v0
li $v0, 1
syscall
li $v0, 10
syscall
function:
move $t0, $a0
li $t1, 0
loop : beq $t0, 0, end
add $t1, $t1, $t0
sub, $t0, $t0, 1
b loop
end: move $v0, $t1
jr $ra
a) What is the value printed by this program (first system call in the program).
b) If register $a0, used for argument passing, stores a value in one-complement,
what is the range of numbers that can be stored in this register?
2. What is the sequence of MIPS instructions that allow implementing the following
sentence in C language? (a and b are int variables)
a = b + c + 100;
3. Consider the following fragment of C code:
for (i=0; i<=10; i=i+1)
a [i] = b[i] + c;
Assume that a and b are arrays of words and that the base address of a is in $t0 and the
base address of b is in $t1. Register $t2 is associated with variable i and register $s0 with
the value of c. You may also assume that any address constants you need are available
to be loaded from memory.
a. Write the code for MIPS.
b. How many instructions are executed during the running of this code if there are
no array out-of-bounds exceptions thrown?
c. How many memory data references will be made during execution?
4. Write a program, using the MIPS 32 assembly language,
a. To calculate the sum of the first 100 numbers. The result must be stored in
register $v0.
b. Print the result.
5. Determine if the number stored in $t2 is even. If $t2 is even the program stores 1 in
$t1, else stores 0 in $t1
Print the result.
6. Write a program in MIPS assembly instructions that reads two numbers. The
program must print what number is the largest.
7. Write a program in MIPS assembly instructions to read a number. The program must
indicate if the number is odd or even.
8. Write a program that reads two integer numbers A and B. The program must
indicate if one of these numbers is multiple of the other one.
9. Write a program to print on the screen number from 1-9.
10. Write a program, using the MIPS32 assembly language that reads a number N and
prints the following:
1
12
123
1234
…..
1 2 3 4 5 …. N
11. Write a function with three arguments. In register $a0 receives the init address of a
string, in register $a1 receives the ASCII code of a char, and in register $a2 receives
the ASCII code of other char. The function must replace in the string any occurrence
of the char stored in $a1 by the char stored in register $a2.
12. Consider the following program. Write an equivalent program, using the MIPS 32
assembly language.
void function1 ()
{
int z;
int array[1024]; // local variable
for (i = 0; i < 1024; i++)
array[i] = i;
z = sum(array, 1024);
print_int(z);
}
int sum(int array[], int n)
{
int s = 0;
int i;
for (i = 0; i < n; i ++)
s = s + array[i];
return s;
}

13. Translate to assembly the following functions:


inf f (int k)
{
int v[100];
int i = 0;
int s = 0;
for (i = 0; i < k; i = i +2)
v[i] = g(k + 2);
for (i = 0; i < k; i = i + 2)
s = s + v[i];
return (s);
}

int g(int k)
{
if (k % 2 == 0)
return (k * k + 2);
else
return k * (-1);
}
14. Let be a 16 bit computer, with byte addressing and a set of 60 machine instructions.
The computer has 8 registers. Show the instruction format for the following
hypothetical instruction ADDV R1, R2, M, where R1 and R2 are registers, and M is
memory address.
15. A 32 bit computer with byte addressing, has 64 machine instructions, and 128
registers. Given the instruction SWAPM addr1, addr2 that swaps the content of the
memory address addr1 and addr2.
a) What is the memory space addressable by this computer?
b) What is the instruction format?
c) Write a program fragment, using the MIPS 32 assembly language, equivalent to
the previous instruction.
d) If the above instruction must occupy one word, what is the range of addresses
that can be addressed by addr1 and addr2?
16. A 32-bit computer with memory addressed by bytes has 64 registers. We want to
design the format for the instructions of this computer, assuming:
- The computer has 115 instructions.
- The execution model in register-register.
- The computer has the following types of instructions:
· Instructions for transferring data between memory and registers. These instructions
use two types of addressing modes: direct, and base-register addressing
· Arithmetic and logic instructions.
· Branch instructions. There are two types of instructions: unconditional to a memory
address, and conditional branches. For conditional branches, the condition is
expressed in a register, and the branch is indicated with PC-relative addressing.
a) Design the format for the instructions of this computer, having into account that
all instructions occupy one word.
b) If the displacement used in the instructions with base-register addressing uses
two-complement, what is the maximum value for these displacements?
c) If the address used in the unconditional branch instructions use binary code
(unsigned), what is the range of addresses for the branch?
d) What is the model of this computer, RISC or CISC?

You might also like