University of Minnesota
Machine Architecture and Organization (sec 010)
index.php

CSci 2021 Lab 0x5

Part 1: Data manipulation puzzles

This section is mostly identical to last week's puzzle lab. There are some minor updates, making it easier to compile the code.

  1. (Lab Setup)

    You can get the handout using the command cp /web/classes/Spring-2020/csci2021/labs/0x4/datalab-handout.tar . , or downloaded from here . Once you have your handout downloaded to one of the cselabs machine, eg: vole.cselabs.umn.edu, unzip the handout using the comand tar -xvf datalab-handout.tar . Use the command, make to compile the code. Verify that an executable btest is created.

  2. ( Solving the Puzzles )

    There are five puzzles that need to be solved, namely, negate, bitAnd, tmax, tmin, replaceByte. In these puzzles, you need to implement the said operations using as few operators as possible. These functions can be updated in the file bits.c . Once you have updated bits.c with your implementation, compile the code using make and run the executable btest. Your score will be output on the terminal, based on correctness. The legality of your solution can be tested using the program dlc. The detailed instructions regarding the implementation of these functions, and testing, can be found in README.

Part 2: Assembly language programming

Most of the way we'll work with assembly language in this course is reading it. That matches the fact that writing large amounts of assembly is no longer very common in the real world: it's much more common for large programs to be written in C or other higher level languages. However low level programming can still often require small amounts of assembly language. Plus it can make it easier to get your head around how a programming language works if you write as well as read it, just like how it's good to practice both listening to and speaking a foreign language at the same time. So in this lab you'll do a little bit of writing x86-64 assembly language functions.

We've given you the framework for a program that includes six functions to be written in assembly language using basic arithmetic and control-flow instructions like we've seen in class. To save you a little work, we've written some testing code in C that will automatically call these functions and check whether they give the expected results. None of these are functions that there would be a real-world reason to write in assembly, we've just chosen them to be small examples that use some of the instructions we've learned so far.

For this part of the lab we've given you two files, funcs.S and funcs-test.c. As usual you can copy them to your own directory with the command:

	cp /web/classes/Spring-2020/csci2021/labs/0x5/{funcs.S,funcs-test.c} .
      

funcs.S is the file where you'll write your assembly code. The .S file extension is related to the .s extension that is used for assembly language code generated by a compiler; the only difference is that the capital S is for assembly code written by people, and is processed with the same pre-processor as C so we can use macros and C-style comments. Comments already in the file give you some ground-rules about what registers to use, as well as describing what each of the functions do. But the implementations of the functions are missing: instead they all just return the number 0. So you'll need to replace the place-holder implementations with the correct ones.

The file funcs-test.c contains code for testing each of the functions in funcs.S. You can also read the test cases here if you want more examples of what the output of the functions should be, but you don't need to put any new code in this file. As we've given it to you, the testing program will stop if it gets to an incorrect result from any of the functions, though you can disable this feature if you want to try the functions out of order. You can compile the assembly-language code and the tests together with a single GCC command like:

      gcc -Wall -g funcs.S funcs-test.c -o funcs-test
    

However if you haven't implemented the first function, the program will stop at the first test case.