Labs

Lab 3 (Assembly Lab)

For this lab, we wrote simple assemble programs. The program given to us printed the message “loop” 10 times. We were to change it to print numbers in ascending order. (First 1-9, then

Assembly is a lot more anal than higher level programming languages (C, C++, Java, etc). You must tell it exactly what to do (gives you higher level of control but responsibility is all on you), how to handle memory etc. Definitely I am more comfortable working with higher level languages as I am already experienced with writing and debugging such programs, compared to Assembly.

The x86_64 version of this lab was run on Xerxes, and the Aarch64 version of this lab was run on Betty.

Assembly seems like it has its uses and is interesting for programmers looking into actual machine code, but I had difficulty writing and debugging the code.

https://github.com/dleung25/Assembler-Lab-3

Lab 4 (Compiled C Lab)

For this lab we wrote a basic C program which printed a message on the screen, Hello World!:

#include <stdio.h>

int main() {
    printf("Hello World!\n");
}

This program is compiled with the following options

-g               # enable debugging information
-O0              # do not optimize (that's a capital letter and then the digit zero)
-fno-builtin     # do not use builtin function optimizations

(1) Added the compiler option -static.

  • Creates standalone application and adds all C libraries to the executable
  • Immensely increases size of file

(2) Removed the compiler option -fno-builtin.

  • Use of “puts” instead of “printf” -> takes only one argument to display the string
  • Results in a slightly faster compile time
  • -fno-builtin tells compiler NOT to use some optimizations, so removing it let the compiler choose to use “puts” to compile quicker

(3) Removed the compiler option -g.

  • Removes debugging information
  • File sizes decreases

(4) Added additional arguments to the printf() function in program.

  • Can add up to 6 in registers for printf before having to push it onto the stack
  • Program speed decreased due to having to pop out each argument from the stack

(5) Moved the printf() call to a separate function named output(), and called function from main().

  • Increases length of process -> main section has to address of “output” to THEN printf (Hello world)

(6) Removed -O0 and add -O3 to the gcc options.

  • From (zero) optimization to maximum optimization
  • Increased size of file

Ending note:

Interesting to dive into using different options to see what the compiler actually does with what you code. (Many new programmers won’t understand why certain things behave the way they do, or how to speed up/slow down compile/runtime).

Lab 5 (Algorithm Selection Lab)

For this lab two algorithms are tested, signed 16-bit integers representing sound waveform samples are multiplied each by a floating point “volume scaling factor” in the range 0.000-1.000. One approach was the naive multiplication of the sample by the volume scaling factor, and the second approach was bit-shifting.

The naive multiplication is very straightforward: multiply each 16-bit integer sample by the volume scaling factor, which was represented by a floating point value. (This is the “naive” step-by-step solution).

This would be represented by your typical for loop:

float vol = 1.0;
for (int i =0; i<sizeOfSamples; i++)

{
samplesArray[i] *= volume;
}

The higher the optimization level, the slower the compile time. code size increases,  execution speed increases.

Both bitwise/naive algorithms can keep up if fed at 44100 samples per second x 2 channels (CD rate).

Both algorithms were similar in speed, with bit-wise edging out naive multiplication at high amount of samples.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s