Difference between revisions of "CSC103 Final Solutions Fall 2012"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- =Assembly= This program provided by Erika is simple, short, and will compute the exact sum. <source lang="asm"> ; CSC 103 Final – Problem 2 ; Erika Miguel ; Compute...")
 
Line 1: Line 1:
 
--[[User:Thiebaut|D. Thiebaut]] 10:11, 31 October 2012 (EDT)
 
--[[User:Thiebaut|D. Thiebaut]] 10:11, 31 October 2012 (EDT)
 
----
 
----
 +
=Boolean Logic=
 +
 +
 
=Assembly=
 
=Assembly=
 
This program provided by Erika is simple, short, and will compute the exact sum.
 
This program provided by Erika is simple, short, and will compute the exact sum.

Revision as of 10:12, 31 October 2012

--D. Thiebaut 10:11, 31 October 2012 (EDT)


Boolean Logic

Assembly

This program provided by Erika is simple, short, and will compute the exact sum.

; CSC 103 Final – Problem 2
; Erika Miguel
; Computes the sum of all the multiples of 3 between 0 and 30
; and stores the result in variable sum.

@0
        jmp start

;
; data section with 2 variables
;

counter: 30
sum:     0

;
; code section
;
start:

; sum <- counter
         lod    counter
         sto    sum

; counter <- counter - 3
loop:
     	 lod    counter
	 sub-c 3
	 sto    counter

; if counter is 0, then jump out of loop

         jmz    done

; sum <- sum + counter

         lod    sum
         add    counter
         sto    sum

; go back to compute new sum

         jmp    loop

; if we reach this point, then we are done with
; the loop and sum should contain the result

done:    hlt

Processing

// D. Thiebaut
// This program displays random circles on the screen when the mouse is pressed.
// When the mouse is pressed and moves to the left, circles shrink, while still remaining
// of random radius.  Similarly, circles grow when the mouse moves to the right, while
// still remaining random in size.

float diameter;

void setup() {
  size( 500, 500 );
  smooth();
}

void draw() {
   diameter = random( mouseX / 2 );
   if (mousePressed == true){
     fill( mouseX/3, random( 255 ), random( 255 ) );
     ellipse( random( 500 ), random( 500 ), diameter, diameter );
   }
}