Difference between revisions of "CSC231 Homework 9 Solution"

From dftwiki3
Jump to: navigation, search
(Dumping the contents of a score file)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
--[[User:Thiebaut|D. Thiebaut]] 19:53, 4 December 2008 (UTC)
 
--[[User:Thiebaut|D. Thiebaut]] 19:53, 4 December 2008 (UTC)
 
----
 
----
 +
<onlydft>
 +
 
__TOC__
 
__TOC__
 +
 +
This is the solution page for [[CSC231 Homework 9| Homework #9]].
 +
 
=Assembly=
 
=Assembly=
 
The solution program is shown below.  Check further down for details on how I created score files and checked their contents.
 
The solution program is shown below.  Check further down for details on how I created score files and checked their contents.
Line 334: Line 339:
 
=Creating Score Files=
 
=Creating Score Files=
  
To create a score file I simply used an assembly file in which I store the score in memory and write the contents of the memory buffer to a file.
+
To create different score files to test the programs, I simply used an already written assembly program that stored a portion of memory to file, and in which I put the score array in memory, a the beginning address associated with the label 'buffer'.  Then it's only a question of writing the contents of the memory buffer to the score file.
  
 
<code><pre>
 
<code><pre>
Line 397: Line 402:
 
noRead  dd    0              ; to store # of chars read from file
 
noRead  dd    0              ; to store # of chars read from file
  
;;; some variables of interest
+
;;; ============= THE SCORES!!! ===============
  
 
buffer  equ    $
 
buffer  equ    $
         db      'ABC'
+
         db      'ABC'                 ; User ABC has Score 10
 
         dd      10
 
         dd      10
 
         db      '233'
 
         db      '233'
Line 456: Line 461:
 
mov ebx,0
 
mov ebx,0
 
int 0x80 ; final system call
 
int 0x80 ; final system call
 
 
;;; ---------------------------------------------------------
 
;;; sleep: assuming a 2 GHz processor, the instruction
 
;;;        for: loop for  should take 1 cycle to execute
 
;;;        since the processor goes through 2E09 cycles
 
;;;        per second, loading ecx with 2000000000 before
 
;;;        the loop should yield something in the order of
 
;;;        a second delay.
 
sleep:  push    ecx
 
        mov    ecx, 2000000000
 
.for    loop    .for
 
        pop    ecx
 
        ret
 
 
  
 
 
Line 614: Line 604:
 
=Dumping the contents of a score file=
 
=Dumping the contents of a score file=
  
This python file was used to display the contents of the score file on the screen.
+
This [[CSC231 dumpScore.py |python program]] was used to display the contents of the score file on the screen.
  
 
<code><pre>
 
<code><pre>
Line 692: Line 682:
  
 
</pre></code>
 
</pre></code>
 +
</onlydft>
 +
 +
[[Category:CSC231]]

Latest revision as of 19:34, 14 September 2010

--D. Thiebaut 19:53, 4 December 2008 (UTC)



...