See the Homework Exercises created by Alan Pinck for this
course. Note: Not all of the Projects are the same between different
sections of this course. Make sure you get the correct Project from your
own section and your own instructor.
See the Lecture Notes created by Alan Pinck for this
Greatest Common Divisor (GCD)
See the GCD pages in: http://www.idcc.net/canisius/cs110sp99/Class04/index.htm
Computer Math and Number Systems
This course requires a background in high-school mathematics: using and doing
math on numbers with exponents, adding and subtracting negative numbers,
converting numbers between different bases, etc. If you need assistance,
the following links may help:
Using DOS DEBUG
Here are some links to descriptions of how to use the DOS DEBUG command:
Saving output from DEBUG
Some of the assignments require you to save the output of DEBUG in a
file. If you're running in a DOS Window under Windows 9x, you can always
use the mouse to copy text and paste it into another application such as
Notepad, Wordpad, or Write. (Do not save the window as a graphic
using Print Screen - the resulting file is huge and unnecessary. Save
the text only, using cut-and-paste into another application such as
Write, Wordpad, or Notepad, and print from there.)
When you print some screen text or programs, you must use a Courier or TERMINAL
fixed-width font. Do not print with a variable-width
font such as Times, Tahoma, or Arial!
If you're running in pure-DOS mode, without Windows, study the examples
below under the heading DEBUG Scripts.
You can enter a few DEBUG commands into a text file, and have DEBUG read the
file and execute the commands while you redirect the output into an output
file. Then, you can print the output files (using a Courier or Terminal
Understanding PUSH, POP, CALL, and INT
The PUSH, POP, CALL, and INT instructions all use the stack (the memory
area pointed at by SS:SP). The following DEBUG scripts and their
annotated output files show what happens. Each of the input files was
run through DEBUG to produce the corresponding output file, to which
explanatory comments were added by hand:
C:> debug <push_pop.txt >push_pop_out.txt
C:> debug <call_push.txt >call_push_out.txt
C:> debug <int_push.txt >int_push_out.txt
Homework, test, and exam questions typically show one of these types of
instructions and ask you to describe which registers and what memory is
affected after the instruction executes (see the Homework questions!).
Your first Intel Assembler programs
See my first Intel programming efforts in the sidebar. First is a
one-page program named onepage.asm that you can
select and download to make sure your assembler and linker are working
correctly. (If you can't assemble and run this simple program without
any warnings or errors, something is wrong with your assembler or linker!)
The command lines I used to assemble and link this program are given in the
comments at the beginning of the program. Either put the ASM and VAL
programs in the same directory as your program, or adjust your DOS PATH
variable to include where they reside. Read the documentation for
details on how the ASM and VAL programs work.
Next is a longer program (mostly comments!) named first.asm
that uses Alan
Pinck's I/O Package. You will need Alan's I/O package in the current
directory on your disk to assemble and run this example. This program is
a good test to see if the I/O package downloaded to your computer correctly.
Also included is Alan's stars.asm program that
prints asterisks based on one key of input, and a modified version of his tail.asm program that displays the Command Tail in the
Program Segment Prefix. The tail.asm program shows how a set of
high-level language statements might be turned into assembler by a compiler
(though this program was translated by hand, not by a compiler).
The program series.asm is a fairly direct
translation of LMC (Little-Man Computer) mnemonic instructions into Intel
mnemonic instructions. The original web page describing this algorithm
is here: http://elearning.algonquincollege.com/coursemat/pincka/dat2343/lect054.htm
Mandatory Program Style
Programs submitted for marking in this course must adhere to the following
|The first line of each program must contain its name. This enables
the instructor to find the program on your diskette, if the assignment
requires you to submit the program on diskette.|
|The author of the program is required. This enables the instructor
to give you a mark for your program. No name - no mark.|
|Assembler programs are written in three columns: Labels, Mnemonics,
and Operands. Programs that choose to put Labels in
column 2 or Mnemonics in column 1 are unreadable and unmarkable.
Follow the example of the sample programs carefully!|
|Comment your code! Unlike high-level languages where you can see
by the names of the variables what manipulation is happening to your data,
assembly language programming involves operations on registers whose names
have no intrinsic meaning in the algorithm. While comments such as
the one following are not useful in any programming language:|
add al,20h ; add 20h to AL (pointless
comments relating to your algorithm are extremely useful:
loop: add al,20h ;
convert uppercase char to lowercase
Comments are required! It is not uncommon to see every line
of an assembler program carry some form of simple in-line comment that
explains how the operation relates to the algorithm being used.
Text editing your ASM Programs
The ASM and MASM assembler programs both insist that files be well-formed,
with proper line end characters on every line, including the last line of the
file. You cannot create a text file using a word processor, unless
you explicitly select "Save as text" when you save the
file. If you use Windows Notepad to build an ASM file, make sure
that the last line of the file ends in a RETURN character. Failure to do
this will result in "premature end of file" errors of this type:
C:> asm /s onepage ;
End of file encountered on input file
onepage.asm(35): ERROR#85 - Premature end of file
Edit the file to add the missing RETURN on the last line of the file.
Reading the file into DOS EDIT and writing it out will fix the problem, as
will reading the file into VIM (an open source version of Unix VI) and writing
it out again.
When in doubt, put a few blank lines at the end of your programs!
If you see programming as a career, you will do well to pick and learn a
proper text editor that has cut buffers, key macros, and global
search-and-replace capabilities. (I use VIM on both Unix and
Windows.) Keyboard and editing skills should not stand in your way of a
Using DOS DEBUG II
The DOS DEBUG command lets you single-step through your programs to debug
them. You can also use it to load raw disk sectors from disks and examine
One of the handy things you can do with DEBUG is prepare small text files
of DEBUG commands (and even include assembler instructions) and run them
through DEBUG using command line redirection to get a quick idea of how
C:> debug <inputcommands >outputfile
See the script file debug_script.txt and its
corresponding output file debug_script_out.txt.
I've edited the output to add comments explaining what I was doing in the
script file, and how to create the script file.
If you're trying to dump disk sectors (as you do in Project 4 in this
course), you may find these kinds of DEBUG scripts, used with command line
redirection, helpful for saving your DEBUG output into files for later
printing: debug_dump.txt debug_dump_out.txt
Tracing COM file programs
DEBUG is able to load and let you single-step through ".COM"
format executables. The quickest way to get the executable loaded into
DEBUG is to give the program you wish to debug as a command argument.
All .COM programs start at segment offset 0100h, so that's where you'll find
your first instructions, ready to be traced:
C:> debug myprog.com
1454:0100 BE8100 MOV SI,0081
1454:0103 803C0D CMP BYTE PTR [SI],0D
1454:0106 7421 JZ 0129
1454:0108 803C20 CMP BYTE PTR [SI],20
1454:010B 7511 JNZ 011E
1454:010D BA2F01 MOV DX,012F
1454:0110 B409 MOV AH,09
1454:0112 CD21 INT 21
1454:0114 83C601 ADD SI,+01
1454:0117 803C20 CMP BYTE PTR [SI],20
1454:011A 74F8 JZ 0114
1454:011C EBE5 JMP 0103
1454:011E 8A14 MOV DL,[SI]
With your program in memory, you are now ready to debug it by single-steping
through it using the "Trace" or "Proceed" commands,
watching the flow of control and the values of the registers.
If you want to supply command line arguments to a program being debugged,
simply add them to your DOS command line when you call DEBUG:
C:> debug myprog.com argument1 argument2 arg3 ...etc...
Using "Trace" vs. "Proceed" in DEBUG
Don't use "Trace" to trace an INT instruction; use
"Proceed" instead. If you trace the INT instruction,
you will end up tracing the call to the interrupt service routine in DOS that
actually performs the interrupt service, and that can be many hundreds or
thousands of instructions! The "Proceed" instruction will not
trace the interrupt service routine; it will simply let it execute (without
tracing each instruction) and it will pause when the service routine returns
to your program.
If a particular disk has 6 surfaces and 50 sectors/track, what is the C/H/S
(Cylinder/Head/Sector) location of absolute disk sector 454 (all values in
Method: Calculate how many full cylinders and tracks precede the given
Our desired sector is number 454, therefore 454 sectors precede it (those
preceding disk sector numbers are #0 through #453 inclusive).
|Calculate the number of full cylinders: C|
Subtract the sectors contained in full cylinders that precede given
Each cylinder contains 6 surfaces times 50 sectors = 300 sectors/cylinder.
Dividing 454 by 300 gives: 1 full cylinder with a remainder of 154
Therefore, one full cylinder precedes sector number 454.
That cylinder is numbered zero, because cylinders number from zero.
Cylinder zero is full, so the cylinder that contains our sector must be
the next (not full) cylinder after cylinder zero. That cylinder is
Therefore: C = 1
|Calculate the number of full tracks: H|
(Each track corresponds to a different surface and a different head.
Track = head = surface.)
Subtract, from the sectors that remain, the sectors contained in full
tracks that precede the given sector.
(These full tracks are in cylinder 1, calculated above.)
Each track contains 50 sectors.
Dividing the remaining 154 sectors by 50 gives: 3 full tracks with a
remainder of 4 sectors.
Therefore, in cylinder 1, 3 full tracks precede sector number 454.
Those 3 tracks are numbered 0,1,2, because the heads (tracks) number from
Tracks 0-2 are full, so the track that contains our sector must be the
next (not full) track after track 2. That track is number 3.
Therefore: H = 3
|Calculate the number of full track sectors: S|
(Reprise: We calculated that cylinder 0 is full; tracks 0,1,2 of cylinder
1 are also full.)
How many sectors remain in cylinder 1, track 3 that precede the given
The remainder of 4 above tells us that, in track 3 of cylinder 1, four
track sectors precede sector number 454.
Those four track sectors are numbered 1,2,3,4, because track sectors
number from one (not from zero).
Track sectors 1-4 are full, so the track sector that contains our sector
must be the next sector after track sector 4. That track sector
number is 5.
Therefore: S = 5
Therefore, disk sector 454 is located at (decimal) C/H/S = 1/3/5