CMSC 313 Project 1

Files:

Instructions for executing the code:

gcc -c cmsc313_proj1.c -o cmsc313_proj1.c.o
nasm -f elf64 -l cmsc313_proj1.lst cmsc313_proj1.asm -o cmsc313_proj1.o
gcc cmsc313_proj1.c.o cmsc313_proj1.o -o cmsc313_proj1
./cmsc313_proj1

Project Details:

The purpose of this project is to transfer content from an array into 4 separate arrays.
The input array stores values in the following sequence:
- Sample 0's x value
- Sample 0's y value
- Sample 0's z value
- Sample 0's o value
- Sample 1's x value
- Sample 1's y value
- Sample 1's z value
- Sample 1's o value
...

There are 4 output arrays (x,y,z,o) that should be loaded with the content from the input array.

The number of samples that need to be transferred is provided in memory location with address samples_cnt.
The input buffer contains 4*#samples integers. Each of the output buffer should contain #samples integers.
Each integer value is 64-bits wide (8 bytes).

There is an assembly file (cmsc313_proj1.asm) and a C file (cmsc313_proj1.c) that are part of the project. 
Only the assembly file should be modified.
The following additional information is in cmsc313_proj1.asm file. There are also a lot of comments/hints and
existing code provided as a guide for the changes needed in the cmsc31_proj1.asm. There are two sections
in the assembly file that can be modified; changes should only be done in the marked section:
- .bss section: optional
- .text section: assembly instructions should be added only inside the section indicated in the code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Start of changes to .text section

    ; End of changes to .text section
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Steps to compile and run the code:
gcc -c cmsc313_proj1.c -o cmsc313_proj1.c.o
nasm -f elf64 -l cmsc313_proj1.lst cmsc313_proj1.asm -o cmsc313_proj1.o
gcc cmsc313_proj1.c.o cmsc313_proj1.o -o cmsc313_proj1
./cmsc313_proj1
Expected output for the samples provided:
85
185
585

cmsc313_proj1.asm should be submitted for the project.

Additional comments provided in the assembly file:
    ; Requirements:
    ; - Transfer the contents from input_buffer into x,y,z,o
    ; - Use [samples_cnt] to determine total number of samples to transfer
    ;   * input_buffer contains 4*[samples_cnt] values in array
    ;     - Each sample contains x,y,z,o information
    ;   * x,y,z,o each should have [samples_cnt] values in array
    ; - Number of values that should be read from input_buffer: 4*[samples_cnt]
    ; - No assumptions should be made about the # of samples (i.e., [samples_cnt] can change)
    ; - Code should be written in assembly (no calls to C function)
    ; - Hints:
    ;   * If rdi == input_buffer, then [rdi]=x[0]
    ;                                  [rdi+8]=y[0]
    ;                                  [rdi+16]=z[0]
    ;                                  [rdi+24]=o[0]
    ;                                  [rdi+32]=x[1]
    ;                                  ...
    ;   * Another way to think about the ordering of the values in array is
    ;                                  [rdi+(0*4+0)*8] = x[0]
    ;                                  [rdi+(0*4+1)*8] = y[0]
    ;                                  [rdi+(0*4+2)*8] = z[0]
    ;                                  [rdi+(0*4+3)*8] = o[0]
    ;                                  [rdi+(1*4+0)*8] = x[1]
    ;                                  ...
    ;   * 'sal rax, 3' can be used to multiply a number by 8 (left-shift by 3 bits)
    ;   * 'inc qword [loop_index]' can be used to increment the variable stored in loop_index
    ;     memory location
    ;   * 'xor rax, rax' initializes rax to 0
    ;   * Temporary values can be stored either in registers (such as rax, rbx) or variables
    ;     can be created in .bss section
    ;   * Take a look at the print_loop code to see how loops can be implemented and values
    ;     can be accessed from arrays
    ;   * mov rbx, [rdi] transfers the value in memory location with address of rdi 
    ;     to the rbx register 
    ;   * mov [rsi], rbx transfers the value in rbx register to the memory location with 
    ;     address of rsi

Back to CMSC313 Home

© Kumaravel Jagasivamani