Computer Fundamentals and MIPS assembly language programming
- Write out the hexadecimal number "ABCD" in binary.
- (a) What is the two's complement 8-bit signed binary representation of the decimal numbers -28 and 16. (b) Show how the numbers can be added together in binary. Convert the answer to decimal.
- How is the number 1.75 held as a single precision IEEE floating point number?
- Imagine a processor with a 16-bit address bus. What is the largest main memory such a processor can support?
- (a) Imagine a processor with 64 registers and 128 instructions. How many bits will be required to encode an instruction that adds the contents of two registers and stores the result in a third register?
- What happens when a processors receives an interrupt?
Assembly Language Exercises
The MIPS processor is described in your "Digital Design and Computer Architecture" book by Harris/Harris. Read about the MIPS processor and then attempt the questions below and the practical exercises using SPIM.
- Describe the journey a typical ALU instruction might take when executing on a simple implementation of a MIPS processor. How is the instruction initially fetched from memory? how are its operands obtained and from where? where is its result finally stored?
- Imagine an array of integers stored in memory that we wish to read one by one. To read the first element we first set a register to hold the address in memory of the start of the array. We then execute a "load word" instruction to transfer the data from memory into one of the processor's registers. In order to load the next element in the array we must add 4 to the current address. Why do we add 4 and not simply increment the address by 1?
- Why does a processor typically have a small set of registers in addition to a large main memory?
- Why isn't the synthetic instruction "la" (Load Address) an actual instruction in the MIPS instruction set?
- What does the program listed below do? Try and guess by looking at the code. If you get stuck you can always run it using the SPIM simulator (see below).
# mystery.s .text .globl main main: la $t0, str1 li $t1, 6 loop: lb $t2, 0($t0) add $t2, $t2, 1 sb $t2, 0($t0) add $t0, $t0, 1 sub $t1, $t1, 1 bnez $t1, loop la $a0, str1 li $v0, 4 syscall li $v0, 10 # exit program system call syscall .data str1: .asciiz "cdbncdd!"
Download the SPIM MIPS simulator by following the instructions here.
If you are using Microsoft Windows, download the ZIP file, open it and run the setup.exe program.
If you are using Ubuntu Linux, type the following to install SPIM:
sudo apt-get install spim
To run SPIM type:
A command line version is also available by simply typing:
Try loading and running the "tick0.s" program (you should be able to download and save the file by right-cliking on the "tick0.s" link, alternative just click on the link and cut-and-paste the code into a text editor.)
Write an assembly language program that takes an array of 10 values and reverses its contents (so A:= A, A:= A, ... A:= A).
I've made a start for you here: "tick1.s"
(I'm stuck! Here is one possible solution to help: tick1-complete.s)
Let's try and sort the elements of the array now. The completed program should print the sorted array (with the lowest number first and highest last). A very simple sorting algorithm that you could use is called 'bubblesort'.
Again, I've made a start for you here: "tick2.s"
(i) Try and write a program that calculates the 1000th prime number.
(ii) Try and find the 1000th prime number without using the "div" instruction.
(iii) Write a subroutine to calculate integer square roots.
(iv) Write a program that multiplies two 32-bit numbers without using the multiply instruction. You only need to calculate the lower 32-bits of the 64-bit result.
References and more examples
Please also refer to the recommended course text books.
"Preliminary Discussion of the Logical Design of an Electronic Computing Instrument", Arthur W. Burks, Herman H. Goldstine and John von Neumann, Institute for Advanced Study, 1946.
It is interesting to read Section 4.1 (The Memory Organ), where the authors identify the need for "constructing a hierarchy of memories, each of which has greater capacity than the preceding but which is less quickly accessible".