IS1200: Exercise CE 1 Nios II Assembly Instructions

advertisement
IS1200: Exercise CE 1
Nios II Assembly Instructions
January 20, 2015
1. Nios II Computer Architecture. Study the assembly programmers’
model of the Nios II.
(a) What registers are in the processor and how are they arranged?
(b) How large is each instruction?
(c) What is the function of the Program Counter (PC)?
(d) How is the program counter updated at each instruction fetch?
2. Different basic types of assembler instructions. The many instructions of the Nios II processor becomes easier to grasp if you group them.
Divide the instructions into the following subgroups.
(a) Instructions to copy data from memory to registers, or vice versa.
(b) Instructions to copy data from one register to another.
(c) Instructions for making an arithmetic operation on two values.
(d) Instructions for making a logical operation on two values.
(e) Instructions to shift or rotate the bit pattern in a register.
(f) Instructions for comparing two values.
(g) Instructions for jumping i.e., changing the program counter.
(h) Conditional jump instructions, which only change the program counter
if the values in one or two registers meets a certain condition.
3. Load and store operations in Nios II. Study load and store instructions in Nios II.
(a) Which addressing modes can be used?
(b) What are the sizes of operands that can be used?
(c) If 4 bytes from memory are copied to a register, what is the order
in which they are written in the register? What order is used when
copying in the opposite direction?
1
(d) If 1 byte of memory is copied to a register, where is it placed in the
register? What happens to the rest of the bytes in the register?
(e) If 1 byte is copied from a register to memory, what happens to the
rest of the bytes in the register?
4. Addition and subtraction operations in Nios II. Study the variations of add and sub instructions in the Nios II processor.
(a) Which addressing modes are used?
(b) What are the sizes of operands that can be used?
(c) Which number representations can be used?
5. The first assembly language program - straight code with load
and store instructions.
Here is a program in Java / C-like code:
1
2
3
int a;
int b;
int c;
4
5
c = a + b;
Write a Nios II assembly language version of the above program. Follow
guidelines below:
A location with the name LABEL is printed first in a line with a colon
(:) after. Example: LABEL:
Use the assembler directive .word 0 to create space for a variable of type
int. Example: x: .word 0
If necessary, use the pseudo instruction movia that causes a 32-bit value
to be written to the specified register. Example: movia r8,4711
It is also possible to use symbolic names instead of numbers. The compiler
translates the symbol name to the correct value. Example: movia r9,
LABEL
6. Comparison instructions in Nios II. Study the many variations of
the cmp instruction in the Nios II processor. How do they work?
7. Unconditional jumps in the Nios II. Study the instructions br and
jmp. How do they work? Which addressing modes can be used?
8. Conditional jumps in Nios II. Study the conditional jump instructions in Nios II. How do they work? What addressing modes can be
used?
2
9. A program with conditional branching. Here is a program in Java
/ C-like code:
1
2
3
int a;
int b;
int c;
4
5
if (a == b) / * then * / c = 17; else c = 4711;
Draw the flow chart of the above program. Create equivalent variants as
indicated below.
(a) A variant that uses an appropriate conditional branch instruction
(and perhaps one or more unconditional jump instructions) but not
the cmp instruction. Draw a flowchart illustrating the variant.
(b) A variant that uses the cmp instruction following a conditional branch
instruction which compares the cmp instruction result with zero (and
probably also needed here are one or more unconditional jump instructions). Draw a flowchart illustrating the variant.
10. A program with a loop.
Here is a program in Java / C-like code:
1
2
3
int n;
int sum;
int i;
4
5
6
7
8
9
sum = 0;
for (i = 1; i <= n; i = i + 1)
{
sum = sum + i;
}
(a) Translate the above program using a while loop.
(b) Translate the while loop program to an equivalent program with the
if and goto.
(c) Translate the if and goto program using Nios II assembly instructions.
3
Download