CPSC 220, Fall 2018
About the First Test


The first test in CS 220 will be given in class on Wednesday, September 26. It will cover everyting that we have done so far, including the labs and the reading. The readings include Chapter 3 from the Larc manual and the following sections from the textbook: Chapter 1, Sections 1, 2, 3, and 6; Chapter 2, Sections 1, 2, 3, 4, 6, 7, and 9.

You should also know about Java's bitwise logical and shift operators (from Lab 1), Larc machine language programming (from Lab2), and the basic ideas of how to write a Larc simulator (Lab 3).

The test will be made up of a variety of questions. There will be some short answer questions and longer essays, ranging from things as simple as the meaning of a single assembly language instruction to very general questions about computers and ISAs. There can be some problems that ask you to write some Lark machine language code, or to say what some given code does. And there can be the same kind of questions about ARMv8 assembly language. Coding questions can include translating Java/C code into machine language or assembly language.

You do not have to memorize the Larc machine language or the Larc assembly language. You will be given a sheet with tables listing Larc machine language and assembly instructions and traps (the tables from pages 23 and 28 in the Larc Chapter 3 handout, and a table of instruction names). I will also include a table of translations from hexadecimal digits to binary and to decimal. For ARM assembly, the list of instructions that you should know is given below. You should memorize them.


Here are some terms and ideas that you should be familiar with:

CPU (Central Processing Unit)
RAM (memory, memory locations, and memory addresses)
ALU (Arithmetic/Logic Unit)
registers
PC (program counter)
how a computer executes a program that is stored in RAM (fetch-and-execute)
how the PC is used during program execution
the "clock" in a computer

ISA (Instruction Set Architecture)
ABI (Application Binary Interface)

binary numbers
counting in binary
hexadecimal numbers
signed and unsigned integers
twos-complement representation of negative numbers

big-endian versus little-endian representation of multi-byte values

bitwise logical operators in Java:  &, |, ~
logical shift operators in Java: >>> and <<
arithmetic shift operator in Java: >>
what's "arithmetic" about the arithmetic shift operator?
using shift and bitwise logical operators to examine one or more bits from a number

Larc, a simple model computer
Larc registers -- 16 16-bit numbers, register 0 is always 0
Larc RAM -- 65536 memory locations, each holding a 16-bit number
Larc machine language
format of Larc machine language instructions
LIMM, SIMM, and sign extension
immediate values
conditional branch instructions (beqz and bnez, opcodes 0xA and 0xB)
traps and the syscall instruction
representation of strings in Larc
accessing memory using load and store (lw and sw, opcodes 0xC and 0xD)
using register zero for: copying a value, unconditional branch
how to write a functional simulator for Larc

the classic performance equation (and the meaning of each term in the equation):
    CPU time = (Instruction Count) X (CPI) X (clock cycle time)

assembly language
how assembly language differs from machine language
mnemonic instruction names
the ARMv8 architecture
what it means that Larc is a 16-bit architecture and ARMv8 is a 64-bit architecture
an ARM instruction is 32 bits long
ARM registers (31 general purpose 64-bit registers, X0 through X30, plus XZR)
ARM memory (one byte per memory location; addresses are 64-bit numbers)
data sizes: byte, halfword, word, doubleword
using register values as addresses in the LDUR and STUR instructions
labels in assembly language programs
how parameters from C functions are passed into an assembly language routine
how a value is returned from an assembly language routine back to the caller
comments in ARM assembly programs

Basic ARMv8 assembly language instructions that you should know
        ADD Xi, Xj, Xk        ADD Xi, Xj, #I
        SUB Xi, Xj, Xk        SUB Xi, Xj, #I
        MOV Xi, Xj            MOV Xi, #I
        LDUR Xi, [Xj,#I]      STUR Xi, [Xj, #I]
        LDURB Xi, [Xj,#I]     STURB Xi, [Xj, #I]
        CBZ Xi, Label         CBNZ Xi, Label
        BL                    RET
        B Label
        CMP Xi, Xj            CMP Xi, #I
        B.GT Label            B.LT Label
        B.GE Label            B.GT Label
        B.EQ Label            B.NE Label


Sample Questions

The following questions are meant as examples of questions that might be on the test. (This is not meant to be a complete survey of every kind of question that you might encounter on the test.)

1. Suppose that A, B, C, D, and E are int variables in Java, and that the following assignment statements are executed. What values are assigned to the variables C, D, and E? Write your answers in hexadecimal.

A = 0x12345678;
B = 0xABCDEFAB;
C = A | 0xFFFF0000;
D = B >> 8;
E = (0xFFFF0000 & A) | (0x0000FFFF & B);

2. Suppose that N is the 16-bit binary number 0b0011010010100110. Write the negation, -N, as a 16-bit binary number.

3. The Larc model computer has 16 registers. How is this number reflected in the format of Larc machine language instructions?

4. Convert the following pseudocode into a Larc assembly language program, with a halt at the end. (You can store N in any register you like. You can write the code using hexadecimal numbers.)

N = 64
while ( N > 0 ) {
  print N
  N = N / 2
}

5. State what each of the following individual Larc machine language instructions does, including which registers and memory locations are affected:

a)  0x1442
b)  1001000100000001
c)  1101000100101111

6. Explain clearly what is done by each of the following individual ARMv8 assembly language instructions.

a)  ADD X1, X1, X9
b)  LDUR X3, [X0, #8]
c)  CMP X0, #100
d)  BL Foo

7. Suppose that a, b, and c are in registers X0, X1, and X2. Translate the following instructions in to ARM v8 assembly language:

a = b + c - a + 7;

8. Translate the following pseudo-code into ARMv8 assembly language, assuming that A and B are stored in registers X0 and X1.

if (A < 10)
   B = A - 7
else if (A < 20)
   B = A
else
   B = A + 7

9. Suppose that a zero-terminated string is stored in memory, and that the address of the first character in the string is stored in register X0. Write ARM assembly code that will find the length of the string and leave the answer in register X0. (The length is the number of characters, not counting the zero at the end.)

10. What is meant by a register?

11. Discuss: How does machine language differ from a high-level programming language such as C or Java?

12. Explain the role of the Program Counter in the fetch-and-execute cycle, and discuss how and why its value changes during the cycle.