[CMSC 313 Home] | [Syllabus] | [Homework] | [Projects] | [Lecture Notes] | [Printable all notes] | [Files] | [NASM resource] |

CMSC 313 Projects

Contents

  • Project 1
  • Project 2
  • Project 3
  • Project 4
  • Project 5
  • Submitting your Project

     The project is to be submitted on  linux.gl.umbc.edu  as 
       submit cs313 proj1 convert.asm
       submit cs313 proj2 math_64.asm
       submit cs313 proj3 plotc.asm
       submit cs313 proj4 proj4.vhdl     or
       submit cs313 proj4 proj4.v
       submit cs313 proj5 proj5.vhdl     or
       submit cs313 proj5 proj5.v
    
     To see what is submitted
       submitls cs313 proj1
    
     To delete a file that was submitted
       submitrm cs313 proj1 convert.asm
    
    
    

    Getting Started

    Using UMBC computer

    From anywhere you can reach the internet:
    
      ssh  your-username@linux.gl.umbc.edu  # or use putty, etc.
      your-password
    
      mkdir cs313   # or whatever directory name you want, only once
      cd cs313      # every time you log in for CMSC 313
    
                    # Get some sample files. (some not needed until later)
      cp  /afs/umbc.edu/users/s/q/squire/pub/download/hello.asm  .
      cp  /afs/umbc.edu/users/s/q/squire/pub/download/intarith_64.asm .
      cp  /afs/umbc.edu/users/s/q/squire/pub/download/xor.circ .
    
                    # be sure to type the final   space dot 
    
                    # you can type in the command lines or get these Makefile's
      cp  /afs/umbc.edu/users/s/q/squire/pub/download/Makefile_nasm .
    
    
                    # test compile  hello.asm
    
      nasm -f elf64 hello.asm      # or just    make -f  Makefile_nasm
      gcc -m64 -o hello  hello.o
      ./hello > hello.out
      cat hello.out
      ls -ltr                 # see files you have
    
    Or type
      make -f Makefile_nasm
      ls -ltr
    
      If this did not work, see Help Desk, T.A. or instructor
    
    

    Project 1, Number Conversion

    Write and submit a NASM assembly language program
    "convert.asm" that implements the number conversions
    that you did for Homework 1.  The file  "intarith_64.asm"
    might be helpful.
    
    You start with two constants in the  .data  section
    
    dec1:  db  '1','2','6','.','3','7','5',0
    bin1:  dq  01010110110111B ; 10101101.10111 note where binary point should be
    
    You convert dec1 to a string of characters that is
    the binary representation of 126.3750 with a binary point
    and three bits to the right of the binary point.
    Print your characters (string) with printf or a kernel call.
    
    You convert bin1 to a string of characters that is
    the decimal representation of  10101101.10111.
    Print your characters (string) with printf or a kernel call.
    
    You may use any method of your choice, and you may print results
    as four numbers: '1','2','6' as 1's and 0's, binary.
    '.','3','7','5' as '.' 1's and 0's binary.
    010101101 as a decimal number, integer
    .10111 as a decimal number, .dddd decimal fraction.
    
    
    submit your file, when it is working correctly,
      submit cs313 proj1 convert.asm
    
    Your file must assemble with no errors and execute
    with the commands:
    
       nasm -f elf64 convert.asm
       gcc -m64 -o convert  convert.o
       ./convert                  # ./ needed if '.' not first in PATH
    
    Then   submit cs313 proj1 convert.asm
    
    Note: '1' is an ASCII character. Subtract 48 from an ASCII
          character to get a binary number. Add 48 to a binary
          number in the range 0 to 9 to get the ASCII character
          '0' to '9'.
    
    '1','2','6' is 1*100 + 2*20 + 6 = 126, binary in a register.
    
    See horner_64.asm for sample loops.
    and loopint_64.asm another sample.
    You do not have to use loops, you can solve just specific problem.
    
    It is OK to process and print one character or digit at a time.
    A snippet of sample code for printing in Nasm:
    
    dec1:	  db  '1','2','6','.','3','7','5', 0
    fmt_char: db "%c",0		; no '\n' thus no 10
    fmt_dig:  db "%1ld",0           ; print just one digit, e.g. 0 or 1
    fmt_end:  db 10, 0              ; just end line
    	
    	mov	rdi,fmt_char	; print a single character
    	mov	al, [dec1]	; byte into bottom of rax
    	mov	rsi, rax	; must go 64-bit to 64-bit
    	mov	rax, 0		; no float
            call    printf
    	
    	mov	rdi,fmt_dig	; print a single character as digit
            mov     rax, 0          ; be safe, zero all rax
    	mov	al, [dec1+1]	; next byte into bottom of rax
    	sub	rax, 48		; change character digit to number
    ;       imul    rax, 10         ; '2' is 20  need to add up 1*100+2*10+4
    	mov	rsi, rax	; must go 64-bit to 64-bit
    	mov	rax, 0		; no float
            call    printf
    
    	mov	rdi,fmt_end	; print end of line
    	mov	rax, 0		; no float
            call    printf
    
    Note:   and     rax,1           ; print with %1ld, prints bottom bit as 0 or 1
                                    ; shr  rax  to get the bit you want
    
    
    Hint, C code, for converting .375 to .011
    frac_bin.c
    frac_bin.out
    Beware rounding when storing double as integer.
    May need  fld, fld, compp  as in ifflt_64.asm
    
    
    Partial credit: 25% for decimal integer to binary
                    25% for decimal fraction to binary
    		25% for binary integer to decimal
    		25% for binary fraction to decimal
    Zero points if your convert.asm does not compile,
                if your convert.asm just prints the answers without
                   doing the conversion.
                if two or more convert.asm are copied
    
      
    

    Project 2, Convert "C" math code to NASM

    Write and submit NASM assembly language functions
    that implement the given "C" functions in math_64.c
    The main program test_math_64.c
    that does not know how the functions are implemented.
    
    The test program is test_math_64.c
    The .h file with function prototypes is math_64.h
    Your correct output should be test_math_64.chk
    
    Note: There is zero credit when  math_64.asm  does not compile without errors.
    
    Your file must assemble with no errors and execute on linux.gl.umbc.edu
    with the commands:
    
       nasm -g -f elf64  math_64.asm  
       gcc -g3 -m64 -o test_math_64 test_math_64.c  math_64.o
       ./test_math_64 > test_math_64.out
       cat test_math_64.out
    
    Then    submit cs313 proj2 math_64.asm
    
    For debugging due to segfault:
        gdb test_math_64
        break main
        run
        step
        step  keep stepping until segfault, thus see where you have a bug
    
        nexti  use in place of   step   to step one instruction at a time
    
    
    

    Your project is to convert math_64.c to math_64.asm

    You may use pre_math_64.asm renamed to math_64.asm as a start. Compile and run to be sure compilation and execution are working, then add project code. All referenced files may be copied to your directory using: Replace xxx.x with the file you want. cp /afs/umbc.edu/users/s/q/squire/pub/download/xxx.x .

    Project 3, plot cos(x)

    
    You are to write a program that does not use "C" functions or libraries.
    This project is based on lecture 8.
    
    You may use system calls or BIOS calls from Lecture 9 to implement the program.
    See hellos_64.asm for compiling, _start
    
    To compile and run your program, use:
    nasm -f elf64 plotc_64.asm
    ld -o plotc_64 plotc_64.o
    ./plotc_64
    
    You only need to print one character at a time, rdx, 1 in syscall.
    Print 10, '\n' at end of each line.
    Or, add one column filled with  10, and print lines=rows.
    
    Your program is to make a simple character plot of  cos(x)
    for x from -Pi to Pi, -3.14159 to 3.14159 in 41 steps, dx = 0.15708
    
    Use 21 rows, middle row for cos(0.0) = 1.0,
    top row for cos(Pi/2) = 0.0, bottom row for cos(-Pi)=cos(Pi) = -1.0
    For each column plotting an '*' at  row k = int(20.0 - (y+1)*10.0)
    
    
    A very small version of the plot would look like:
          *                     9 columns, 7 rows
         * * 
       
        *   *  
     
       *     *
      *       *
    
    Compute cos(x) in your program  y = cos(x) =
    1 - x^2/2! + x^4/4! - x6^/6! + x^8/8!
    OK to use code from horner_64.asm float
    af: dq 1.0, 0.0, -0.5, 0.0, 0.41667, 0.0, -0.001389, 0.0. 0.000025 
    N:  dq 8
    XF: x=0, x=x+dx   dx = 0.15708 
    This computes YF = cos(XF)
    	mov	rcx,[N]		; loop iteration count initialization, n
    	fld	qword [af+8*rcx]; accumulate value here, get coefficient a_n
    h5loop:	fmul	qword [XF]	; * XF
    	fadd	qword [af+8*rcx-8] ; + aa_n-i
    	loop	h5loop		; decrement rcx, jump on non zero
    	fstp	qword [Y]	; store Y
    
    Then compute kf = 20.0 - (Y+1.0)*10.0  floating point
    Then store k as integer:   fistp  qword [k]
    Then compute double subscript, integer, k*ncol+j  in rax
    Then store star:
          mov  bl, [star]
          mov  [a2+rax], bl  
    
    Note: For printing  mov  rsi, rax // syscall (rcx for  int) 
                        add  rsi, a2  // not [a2+rax] need address
    
    If it runs to your satisfaction,
    Then    submit cs313 proj3 plotc.asm
    
    The program in "C" is 
    See plotc_64.c for possible method
    See plotc_64.outc "C" output
    See plotc_chk.out Nasm output
    See hornerc_64.asm for computing cos(x)
    
    // plotc_64.c  simple plot of cos(x)
     #include <stdio.h>>
    
     #define ncol 41
     #define nrow 21
     int main(int argc, char *srgv[])
     {
       char points[nrow][ncol]; // char == byte
       char point = '*';
       char space = ' ';
       long int i, j, k;
       double af[] = {1.0, 0.0, -0.5, 0.0,
                      0.041667, 0.0, -0.001389, 0.0, 0.000025};
       long int n = 8;
       double x, y;
       double dx = 0.15708; // 6.2832/40.0
    
       // clear points to space ' '
       for(i=0; i=0; i--) y = y*x + af[i];
         k = 20 - (y+1.0)*10.0; // scale 1.0 to -1.0, 0 to 20
         printf("x=%f, y=%f, k=%d \n", x, y, k);
         fflush(stdout);
    
         points[k][j] = point;
         x = x + dx;
       }
    
       // print points
       for(i=0; iNasm code for loops to clear and print array of characters
    
    array2_64.asm sample code
    array2_64.out output
    
    snippet of code, double loop, to clear array
    (ultra conservative, keeping i and j in memory)
    
    These 3 lines of "C" code become many lines of assembly
       // clear points to space ' '
       for(i=0; i<nrow; i++)
         for(j=0; j<ncol; j++)
           points[i][j] = space;
    
    	
    	section .bss            ; ncol=7, nrow=5 for demo
    a2:	resb 	21*41		; two dimensional array of bytes
    i:	resq 	1		; row subscript
    j:	resq 	1 		; col subscript
    k:      resq    1               ; row subscript computed
    
            SECTION .text           ; Code section. just snippet
    
    ; clear a2 to space
    	mov 	rax,0		; i=0  for(i=0;
    	mov	[i],rax
    loopi:
    	mov	rax,[i]         ; reload i, rax may be used
    	mov 	rbx,0		; j=0  for(j=0;
    	mov	[j],rbx
    loopj:
    	mov	rax,[i]         ; reload i, rax may be used
    	mov	rbx,[j]         ; reload j, rbx may be used
    	imul 	rax,[ncol]	; i*ncol
    	add  	rax, rbx	; i*ncol + j
    	mov 	dl, [spc]	; need just character, byte
    	mov 	[a2+rax],dl	; store space
    
    	mov	rbx,[j]
    	inc 	rbx		; j++
    	mov	[j],rbx
    	cmp 	rbx,[ncol]      ; j<ncol
    	jne 	loopj
    
    	mov	rax,[i]
    	inc 	rax		; i++
    	mov	[i],rax
    	cmp	rax,[nrow]	; i<ncol
    	jne 	loopi
    ; end clear a2 to space
    
            ; j = 0;
            ; xf = X0;
    
    From horner_64.asm  use
    
    cos:	mov	rcx,[N]		; loop iteration count initialization, n
    	fld	qword [af+8*rcx]; accumulate value here, get coefficient a_n
    h5loop:	fmul	qword [XF]	; * XF
    	fadd	qword [af+8*rcx-8] ; + aa_n-i
    	loop	h5loop		; decrement rcx, jump on non zero
    	fstp	qword [Y]	; store Y
    
            ; k = 20.0 *(Y+1.0)*(-10.0)  fistp qword [k]
            ; rax  gets  k * ncol + j
            ; put "*" in dl, then dl into [a2+rax]
    
            ; XF = XF + DX0;
            ; j = j+1;
            ; if(j != ncol) go to cos
    
            ; copy clear a2 to space
            ; in jloop renamed, use  syscall print from hellos_64.asm
            ; add rax,a2   replaces  dl stuff
            ; mov rsi, rax (moved up) replaces  mov rsi, msg
            ; replace any  len  with  1 
    
            ; after jloop insert line feed  lf: db  10
            ; mov rsi, lf  in lpace of mov  rsi, rax
    
            ; use  exit code from  hellos_64.asm
            ; no push or pop  rbx
    
    in  .data  
    af:	dq	1.0, 0.0, -0.5  ; coefficients of polynomial, a_0 first
    	dq	0.0, 0.041667, 0.0, -0.001389, 0.0, 0.000025
    XF:	dq	0.0		; computed
    Y:	dq	0.0		; computed
    N:	dq	8		; power of polynomial
    X0:	dq	-3.14159	; start XF
    DX0:	dq	0.15708		; increment for XF  ncol-1  times
    one:    dq      1.0
    nten:   dq      -10.0
    twenty  dq      20.0
    
    
    Your  plotc.asm  can not use printf or any "C" functions.
    Thus you use   global _start   and  _start:  in place of
                   global main     and  main:
    
    ; compile using   nasm -g -f elf64 plot.asm
    ;                 ld -o plotc_64  plotc_64.o        # not  gcc
    ;                 ./plotc_64  >  plotc_64.out
    ;                 cat  plotc_64.out
    
    

    Project 4, Digital Logic

    Use VHDL or Verilog:
    For Vhdl:
    Use proj4.vhdl as the start of
    project 4. Everything has been provided to build and test a
    4-bit times 4-bit unsigned parallel multiply. In order to have
    less VHDL, a "madd4" entity was created. The multiplier can now
    be built from exactly four of the "madd4" entities.
    (Slightly different from multiplier used in the lecture.)
    
    The first "madd4" is in the file. You must code the three
    remaining "madd4" and code the "dot" merge of "cout" with
    the top three bits of the "sum", and the product bits "p".
    
    
    Notes: Each box is a  madd4  entity.
    
           The boxes should be labeled a0:, a1:, a2: and a3:.
    
           The  cout  signals are named  c(0), c(1), c(2) and c(3).
           The  sum   signals are named  s0, s1, s2, p(6 downto 3).
           The dot where three wires join the cout wire is
           coded in VHDL as  s0s <= c(0) & s0(3 downto 1);
    
           The  s0s  4-bit signal goes into the  madd4  'b' input.
           The first 'b' input must be four zero bits, signal zero4.
    
           The low order product bit, p(0) is the bottom bit
           of  s0  and is coded in VHDL as  p(0) <= s0(0);
    
    For Verilog:
    Use proj4.v as the start of
    project 4.
    
    This is a modification of mul4.v
    Fill in module  madd4 using four madd modules.
    Then instantiate four madd4 to build the circuit.
    
    Your output should have correct 1 or 0 in place of "z"
    proj4_v.out
    proj4_v.chk
    
    Other sample Verilog files
    add4.v
    mul4.v
    

    Using Cadence VHDL or Verilogon GL machine

      First: You must have an account on a GL machine. Every student
             and faculty should have this.
             Either log in directly to linux.gl.umbc.edu or
             Use   ssh  linux.gl.umbc.edu
    
             Be in your cs313 directory, else files must be changed.
             You can copy many sample files to your working directory using:
             cp /afs/umbc.edu/users/s/q/squire/pub/download/cs313.tar  .
             There are many files available.
    
      Next:  Follow instructions exactly or you figure out a variation.
      1)     Get this tar file into your home directory (on /afs  i.e.
             available on all GL machines.)
             cs313.tar   and then type commands:
             cp /afs/umbc.edu/users/s/q/squire/pub/download/cs313.tar  .
             tar -xvf cs313.tar
             cd vhdl
                         fix cds.lib to have correct path
             source vhdl_cshrc
             make
             more add32_test.out
             make clean              # saves a lot of disk quota
    
             If verilog does not run, use command:
               source /afs/umbc.edu/software/cadence/etc/setup_2008/cshrc.cadence
    
             Then do your own thing with Makefile for other VHDL files
    
             You are on your own to write VHDL or Verilog and modify the Makefile.
             Remember each time you log on:
             cd vhdl
             source vhdl_cshrc
             make                        # or do your own thing.
    
    Now work project 4:
      Run the following commands:
      cp /afs/umbc.edu/users/s/q/squire/pub/download/proj4.vhdl  .
      cp /afs/umbc.edu/users/s/q/squire/pub/download/proj4.run  .
      cp /afs/umbc.edu/users/s/q/squire/pub/download/proj4.chk  .
      cp /afs/umbc.edu/users/s/q/squire/pub/download/proj4.make  .
    
      You should get some results from the command
      make -f proj4.make
     
      or verilog -q -l proj4_v.out proj4.v
    
      Lots of "U" until you insert the VHDL for the project.
    
      Now, work the project.
    
      You do the submit,  submit cs313 proj4 proj4.vhdl  or
                          submit cs313 proj4 proj4.v
    
      check your products by hand or computer
    
    
    
    

    Project 5, Digital Logic

    Finish up the design and finish up the implementation
    of a six bit spin lock.
    
    You are given a starter VHDL file proj5.vhdl
    
    Or, use the given starter Verilog file proj5.v
    
    The spin lock is given by
    
    
    Use names A, B, C, D, E, F for the spin lock, there
    is debug print in proj5.vhdl and proj5.v   for testing.
    Initialize all D flip flops to '0' except set A to '1'.
    Be sure to compute "activate" along with the Ain, Bin, etc.
    The test input has the name  "rcvr" and has 10 entries.
    The code to be detected is 6 bits in the middle.
    
    The entity dff1 in VHDL, module dff6 in verilog,  is used by
    the spin lock is ready to use in
     proj5.vhdl. The circuit symbol is:
    The module dff6 that is used by the spin lock is ready to use in
     proj5.v. similar circuit symbol.
    
    Your project is to finish the VHDL or verilog code for the spin lock.
    Look for  "???"
    See lecture notes Lect 23
    for method of converting a sequential circuit to digital logic.
    The lecture notes have legal VHDL statements, e.g Ain <= ... ; 
    The Verilog uses  Ain = ...;
    
    Code the digital logic in VHDL and add the VHDL statements
    into proj5.vhdl
    
    Copy files into your  vhdl  directory with the following commands:
      cp /afs/umbc.edu/users/s/q/squire/pub/download/proj5.vhdl  .
      cp /afs/umbc.edu/users/s/q/squire/pub/download/proj5.run  .
      cp /afs/umbc.edu/users/s/q/squire/pub/download/proj5_vhdl.out  .
      cp /afs/umbc.edu/users/s/q/squire/pub/download/proj5.make  .
      You should get some results from the command
      make -f proj5.make
    proj5_vhdl.chk  .
    
      Lots of "U" until you insert the VHDL for the project.
    
    
    For Verilog
    Copy files into your  vhdl  directory with the following commands:
      cp /afs/umbc.edu/users/s/q/squire/pub/download/proj5.v  .
    
    Run with  verilog -q -l proj5_v.out proj5.v
    output before adding project proj5_v.out  . 
    
      Now work project 5.
      Then    submit cs313 proj5 proj5.vhdl   or
              submit cs313 proj5 proj5.v
    
    proj5_v.chk  .
    
    

    Files to download and other links

    Course links

    Go to top

    Last updated 7/26/2015