Assembly & Machine Language
In-class Exercises


Use the Assembly Language instructions you used in the CPU Simulator for the following exercises.

(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 40 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 44 and 48, 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 40 and 44 as x and y. It's possible to capture this in a single line of JavaScript or Python.)
                LOAD R2 M40
                ADD R2 R2 R2
                LOAD R1 M44
                ADD R3 R1 R2
                STORE R3 M40
                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.)
                Mem[16] = Mem[12] + R2 - R3
    
    
    
    
    
    
            
  5. (optional) Write the instructions for exercise 1 in machine language (binary).