Assembly & Machine Language
In-class Exercises


Use the "Simple Instruction Set" beneath this Simple CPU Simulator for the following exercises. Recommendation: Bring up the simulator in a separate, side-by-side browser window and scroll down until you find the instruction set for this miniature assembly language.

(Here's a Markdown template for this mini-lab, if you want to use it.)


  1. Write the assembly language instructions to add the contents of memory location 7 to the contents of register 2 and store the results in register 0. Note: Are you allowed to add the contents of a memory location to a register? Or do you need to load the value from memory into another register first? How many instructions will you need to complete this task? By the way, this is clearly just a small program snippet rather than a whole program (since it assumes one value is already in a register and leaves the result in another register), so there is no need to add a HALT instruction.
    
    
    
    
    
            
  2. High-Level Language ⇒ Assembler: What would be the assembly instructions to do the following computation? (Assume that x and y are in memory locations 6 and 7, respectively.)
                y = x + y;
    
    
    
    
    
            
  3. Assembler ⇒ High-Level Language: Determine what the following assembly language program fragment does. What would the same program fragment look like in JavaScript or Python? (You may refer to the contents of memory locations 5 and 6 as x and y. It's possible to capture this in a single line of JavaScript or Python.)
                LOAD R2 5
                ADD R2 R2 R2
                LOAD R1 6
                ADD R3 R1 R2
                STORE R3 5
                HALT
    
    
            
  4. What would be the assembly instructions to do the following computation? (This notation is neither a high-level language nor assembly language, but sort of a compromise between them.)
                R0 = Mem[7] + R2 - R3
    
    
    
    
    
    
            
  5. (optional) Write the instructions for exercise 1 in machine language (binary).