Starting from:
$35

$29

CEG 3310 Lab 2 – Simple Programs

Learning Objectives

    • Understand writing simple programs in the LC3 simulator

    • Learn the interface of the LC3 simulator and editor

Overview

You will be implementing simple loops, if statements, and mathematical operations in assembly.

The Programs

You will be writing 4 separate programs in assembly for the LC3:

    1. Write a program that calculates the result of z = xy

        a. Store x and y in memory locations when writing your program (use .FILL)

        b. The output of your result, z, should be left in register R3 at the end of your program

        c. Assume (6 >= x >= 0) and (6 >= y >= 0)

    2. Write a program that implements a for loop that adds 5 to R3 every iteration

        a. Increment a register by 1 in every cycle of the loop to keep track of the loop iterations

        b. Store the maximum amount of iterations that the loop can have in a memory location

        c. Your for loop should start at 0 iterations (i.e. i = 0) and stop looping once the maximum is reached

    3. Write a program that implements a while loop

        a. Loop while(R0 > -10)

        b. For every iteration of the loop subtract 2 from R0

        c. R0 should start at 0

    4. Implement an if-else statement

        a. An if-else statement will execute one out of two blocks of code

        b. Your if-else statement should check if R0 = R1, then make R3 = 5, if R0 ≠ R1, then make R3 = -5

        c. You can manually modify R0, R1, and R3, in the simulator (before running your program only). You do not have to program values for these registers

Assignment

Complete the 4 previously mentioned programs in a .txt file. There should be 4 .txt files uploaded for your submission titled: exponent.txt, for.txt, while.txt, and ifelse.txt. Please use a zip file to contain all these .txt files titled: YOUR-LAST-NAME-Lab2.zip

Make sure you test your programs in the simulator before submitting. If you cannot solve one or more of the programs, please try the others. Partial submissions will be accepted and programs that are incomplete can still earn some points.

Hint: use the sample code in the slides to your advantage!

Grading

This lab is worth 40 points, distributed as follows:


Task
Points

Successfully implement an exponential function
10

Successfully implement a for loop
10

Successfully implement a while loop
10

Successfully implement an if-else statement
10

More products