|
COSC 2410
|
|
Course Information:
|
Course Name:
COSC 2410 - Computer Organization and Programming
Prerequisites:
COSC 1410 - Introduction to Computer Science
Professor:
Dr. Dragan Mirkovic
Professor email:
mirkovic@cs.uh.edu
Professor office:
TBD 221 PGH
Lectures:
1-2:30 T/TH 232 PGH
TA:
Colin Puri
TA email:
automata@cs.uh.edu
TA office:
4 - 5 T/TH 566 PGH
Labs:
11:30-1, 2:30-4 T/TH 563 PGH
|
|
|
|
Textbooks:
|
|
|
|
Course Web Pages:
|
|
|
|
Links:
|
|
|
|
Optimized for Microsoft IE in 1024x768
|
|
|
|
Frequently Asked Questions
Lab
Operating System
Programmers Workbench (PWB)/MASM
Programming
Lab
Operating systems
- How do I open a command prompt/DOS window
A command prompt/DOS window can be opened simply by navigating with
the mouse to the "Start" button located on the task bar and pressing with the left mouse button.
Choose "Run", and left click on the mouse. You will immediatly be presented with a box titled "Run"
and the following text "Type the name of a program, folder, document, or Internet resource, and Windows will open it for you."
This message is then followed by a text box in which you can type. Now type "command" and press the enter key or click the "OK" button
with you left mouse button. Shortly thereafter you will be presented with a command prompt/DOS Window
back to the top
- When in a command prompt/DOS window, how do I change directories?
To change directories simply type "cd [DESTINATION DIRECTORY]" where the destination directory is the name of the directory you wish to navigate to
back to the top
- How do I create a directory in a command prompt/DOS window or through the Windows Explorer?
To create a directory in a command prompt/DOS window you will first need to open a DOS window (described above). Once you have
done this you need to navigate to the directory that you wish to place the new directory in (described above). Once you have gotten
this far you simply type the following "md [NEW DIRECTORY NAME]" where you specify the name of the directory you would like to create
by replacing the "[NEW DIRECTORY NAME]" in the preceding string with the name you want. Then hit the enter key. You have now created
a new directory.
To create a new directory in Windows or the Windows Explorer you need to first launch the windows explorer and navigate to the directory
that you would like to contain the new directory that you want to create. Once you have reached this location in the Windows Explorer
simply right click on any part of the empty space in the directory window and move the mouse to the "New" and select "Folder." A folder
with the name "New Folder" will appear. This folder will be highlighted and will be waiting for you to rename it to whatever you like.
If you choose not to rename it, it will remain with the name "New Folder." You have now created a folder using the Windows Explorer.
back to the top
- How do I create a text file in Windows? What about in a DOS environment?
To create a text file in Windows you must first navigate to the specific area that you would like to store the text file using the Windows
Explorer. Once you have done this, right click on any empty location in the explorer window for that location and move the mouse cursor to
"New." Then choose "Text Document." Having done this, a new text file has now be created, but needs to be named. You can either leave it
with the name "New Text Document.txt" or rename by typing in a new name now. You have now created an empty text file.
To create a text file in DOS you will need to first be in a DOS window and have already navigated to the specific directory in which you
would like to store the text file (see above). Having done this, simply type "edit [FILENAME]" where you will replace "[FILENAME]" in the
preceding string with the name of the file you would like to create. An editor will be launched and you can now edit the file and then save it
back to the top
- How do I delete a file in Windows? What about in a DOS environment?
To delete a file in Windows you need to first navigate to the directory in which the file is contained. Once there, find the file in question
and select it by left clicking it once with the mouse. It will be highlighted at this point and you can now hit the delete key or right click
the mouse and choose "Delete." You will be immediately presented with anothe popup box asking if you are sure you want to delete the file.
Choose "Yes." You have now deleted the file.
To delete a file in DOS you first need to navigate to the particular directory in which the file in question is contained. Once there type the
following command "del [FILENAME]" where "[FILENAME]" is replaced in the preceeding string with the name of the file that you want to delete.
When you have typed this at the command prompt, hit the enter key. You have now deleted the file in DOS.
back to the top
- How do I move a file in Windows? What about in a DOS environment?
To move a file in Windows you first need to navigate to the directory in which the file is located using the Windows Explorer. Once there,
right click on the file in question and select "Cut." After doing this, you will need to navigate to the destination directory (using Windows
Explorer) where you would like to place the file. Once there right click with the mouse on any location in the directory and select "Paste."
You have now moved a file.
To move a file in DOS, pull up a command prompt/DOS window (see above). At the command prompt type the following "move [SOURCE] [DESTINATION]"
where "[SOURCE]" is the location and name of the source file and "[DESTINATION]" is the destination location where you would like the file name.
After typing the information in, press enter. You have now moved the file.
back to the top
- How do I rename a file in Windows? What about in a DOS environment?
To rename a file in Windows simply right click on the file in question and select properties. You will be presented with the properties box.
On the "General" tab, there is an text input box with the name of the file. You can change the name of the file by click on this text box and
typing in the name of your choice. Once you have done this, click the "OK" button located at the bottom of the window with the left mouse button.
You have now renamed the file.
To rename a file in DOS, type the following command "rename [SOURCE] [DESTINATION]" where the "[SOURCE]" is the name of the original file and
"[DESTINATION]" is the name you would like to change the file to. After typing this press the enter key. You have now renamed the file.
back to the top
- How do I copy a file in Windows? What about in a DOS environment?
To copy a file in Windows you first need to navigate to the directory in which the file is located using the Windows Explorer. Once there,
right click on the file in question and select "Copy." After doing this, you will need to navigate to the destination directory (using Windows
Explorer) where you would like to place the file. Once there right click with the mouse on any location in the directory and select "Paste."
You have now copied a file.
To copy a file in DOS, pull up a command prompt/DOS window (see above). At the command prompt type the following "move [SOURCE] [DESTINATION]"
where "[SOURCE]" is the location and name of the source file and "[DESTINATION]" is the destination location where you would like the file name.
After typing the information in, press enter. You have now copied the file.
back to the top
- How do I save the output of command that I have executed?
To save the output of a command that you have executed you must first open a DOS command prompt. At the command prompt type
"[EXECUTABLE] > [DESTINATION FILE]" and press enter. The string "[EXECUTABLE]" is the name of the command which you wish to save the output of.
The string "[DESTINATION]" is the name of the file in which you wish to store the output. Once you have pressed enter, you have saved the output
to a file with the name in which you specifed in the destination.
back to the top
- When I work in a command prompt/DOS window I do not have mouse input available. How can I access the menu of some DOS programs without the mouse?
In most cases programs that run in DOS can be accessed by pressing two keys together. Generally the keys to be pressed are a combination of the
"Alt" key and some other key. In most cases the second key to press is the first letter of the menu label that you wish to access. Other ways
to determine what the second key is is to look for an letter that is underlined or capitalized in the menu label. For example, you look at the DOS program
"Edit" you can access the "File" menu by pressing "Alt+F." That is, you need to press the "Alt" key in conjunction with the key labeled "F."
The following key cominations are required to access the following menus in "Edit":
File - Alt+F
Edit - Alt+E
Search - Alt+S
View - Alt+V
Options - Alt+O
Help - Alt+H
Key combinations that allow for quick access to the menu of a program are generally refered to as hot-keys or menu shortcuts
back to the top
Programmers Workbench (PWB)/MASM
- How do I install MASM 611 and what do I need to do to configure it to run on my machine?
If you are installing MASM from the provided CD in the text book you can do one of two options that are the most efficient. On the CD there are 5 directories
that contain the contents for MASM 611 per disk (i.e. "MASM611 1," "MASM611 2,""MASM611 3," etc.). You need to take the contents of those directories and copy
them to a single directory on your machine. Be sure to keep the directory structure within those disk directories intact when copying. In otherwords, in the
CD directory "MASM611 1" there are several files and a "Bin" directory, when copying to the destination on your harddrive you must also copy the "Bin" directory
and its contents to a "Bin" directory in the destination directory of your harddirve. Do this for all five disks. The other option is to copy each of these
directories to seperate disks and run setup from the first disk. When you are done, goto the directory in which you copied (or the first disk to which you copied)
and execute "Setup.exe." You will be asked several questions including the destination directory to which you would like to install MASM 611. I advise you to leave
everything as default as it will make the process much easier. You will be asked a series of questions, you can just hit enter for all of them. At some point it will
finish (if you chose the disk option, you will have to follow directions and change disks when it asks). You will know that you are finished when you have reached
a menu that has numerous options, including "Exit." Choose "Exit." Now you need to configure your machine to run MASM 611.
There are two ways to do this, you can either edit your "Autoexec.bat" file located in the root directory of your machine or you can create a shortcut in MS Windows and
specify a startup file for it. If you are running Windows 95 and up, I recommend that you choose the latter option. If you are running under earlier versions of windows
(Windows for Worgroups 3.11 and under) or DOS then you will need to choose the former option. Windows 95 and up can be configured using either option. If you are using
any other OS's then you need to figure it out on your own.
To configure the "Autoexec.bat" option you need to get to a command prompt and navigate to the root directory (refer above if you do not know how to do this).
Type "Edit autoexec.bat" at the command prompt. There may be several lines in this file already, if this is the case find a line labelled something to the effect
"PATH=....." where you are looking for a line starting with "Path." If you have such a line then at the end of it place the following text ";C:\MASM611\BIN;C:\MASM611\BINR"
If you do not have this line you will have to add it your self by typing "PATH=%PATH%;C:\MASM611\BIN;C:\MASM\BINR;" Now you need to add the environment variable "INCLUDE"
to this file as well. On a seperate line type the following "SET INCLUDE=C:\MASM611\INCLUDE" You are now done configuring your computer to run MASM611 and you will need to
reboot in order for the changes to take effect.
If you are running Windows 95 and above you can ALSO configure it to run a seperate startup file everytime MASM 611 is executed. To do this, create a shortcut for "PWB.EXE"
somewhere in your computer (i.e. your desktop). "PWB.EXE" can be found in the "C:\MASM611\BINR" directory (this may differ if you did not install MASM to the default directory).
With this done, right click on the shortcut that you have just created and choose "PROPERTIES." You will be presented with a window containing several tab options at the top
of it. Click on the "PROGRAM" tab. At this point you will see an "ADVANCED" button near the bottom of the window, click on it. You will be presented with another window containing
two text boxes. The text input box with the label "Autoexec filename," is the one you will need to change. Place the following string in the input box "C:\MASM611\BINR\NEW-VARS.BAT"
and click "Ok", then click "Ok" on the window properties window. You have now configured your Windows OS to run MASM (there is NO need to reboot).
If you are running Visual Studio on your computer and you are modifying the "autoexec.bat," file then make sure that the path for MASM is located at the end of the path statement
back to the top
When I am using the PWB editor, the keyboard goes crazy and suddenly puts a lot of characters on the screen when I'm typing.
What is causing this problem and how can I fix it?
This problem is common and is a result of default setting of PWB. PWB has editor variables, flags, and boolean values
that it uses to control its operation. The problem in question occurs when a user depresses a key on the keyboard for too long
resulting a character being repeated at a high rate. Luckily this can be fixed. There are flags in the editor, labeled "fastfunc,"
that need to be turned off. After launching PWB navigate the menues to "Options->Editor Settings..." YOu will be presented with
box labelled editor settins. On the right side of the box there is a sub-box labelled "Switch type" Using the mouse (you may also use the keyboard if
you are familiar with navigating using the keyboard), select the "text" option. Upon doing this, the "Switch list" box (located below) will
change its contents. Using the scroll bar on the right of the "Switch text" box scroll down until you encounter a line that begins with the word
"fastfunc:" Again, using the mouse (or keyboard) select this text flag by clicking on it. When you do this, a line
at the very top of the "Editor Settings" box will change to display the value of the flag selected. In this case, if this is your first attempt to change
a "fastfunc" flag then the line will read "fastfunc:cdelete on" Now, that you have this flag selected, go ahead and change the flag from
"fastfunc:cdelete on" to "fastfunc:cdelete off" and then click the "Set Switch" button located at the bottom of the "Editor Settings" box. Proceed to do this
for all of the "fastfunc" variables by changing the last part of the switch name from "on" to "off" and selecting "Set Switch" each time you do so.
Once you have done this you need to select the "Save..." button located at the bottom of the "Editor Settings" box. You will be presented with a
"Modified Switch List" box, select "OK." Now you are returned to the "Editor Settings" box, select "OK." You have now modified the fastfunc settings for PWB
and the fast repeat rate for a keystork will not happen again.
back to the top
- When trying to build my program in PWB, I get the following error "LINK : warning L4050: file not suitable for /EXEPACK; relink without." What does it mean and how do I fix it?
This means that you have the "/EXEPACK" option enabled when linking. What this option attempts to do is remove null spaces from the final executable and is an
option that is enabled when trying to compile and linke for release. To remedy this problem you need to change your build options to "Debug" or remove the "/EXEPACK"
option. To set the build options go to "Options->Build Options." You will be presented with a new window asking for the options to be either "Debug" or "Release."
Choose "Debug" and then click "OK." You can now relink without having that problem.
back to the top
- When trying to build my program in PWB, I get the following error "fatal error A1000: cannot open file : bios.inc." What does this mean and how do I fix it?
This is what happens when you do not have your "INCLUDE" variable set. To set this you need to exit PWB and find the shortcut on your desktop for PWB. Right click the
PWB shortcut and select "Properties." On the "Program" tab, click the "Advanced" button. You will be presented with a new popup window with two text boxes. You will
need to change the value in the first textbox labled "Autoexec filename: " In the text box put the following string instead of the default that is already there,
"C:\MASM611\BINR\NEW-VARS.BAT" You will now be able to compile without a problem once you RESTART PWB.
back to the top
- How do I create project in PWB?
You can do this by going to Project->New Project and then typing in
a name for the project name (be sure not to have it as
the same name of your source file. i.e. if your source
file is called "welcome.asm" DO NOT name your project
"welcome.asm" since it will overwrite the source file
if you store the project and the source file in the
same directory). Now click "Ok." Once you have done this, then find
your source file and add it to the project. you will
be presented with an opportunity to do this after you
have created a project name and selected "ok." Once
you have added files to the project (to add, once you
find the source file you can double click it) select
"save list" you can now compile, link, and excute, if
you goto project->build then you can execute the code
after it compiles and links it (compile and link are
done at the same time by the build option if you have multiple files). After you
select build, assuming there are no errors, you can
click the "run program" option from the window that
will pop up.
back to the top
Programming
- In the "welcome.asm" Assembly program example, you used the instruction "int 21h." What is it for? Are there other instructions of this type?
There instruction "INT" means interrupt. There are two kinds of interrupts: a hardware interrupt, and a software interrupt. A hardware interrupt is a signal generated by
a system device that indicates immediate attention to is requested from the CPU. When a hardware interrupt is thrown, the execution of the current program is suspended
while the interrupt is processed. A software interrupt is a request to a BIOS or DOS service routine. In the strictest sense, there are no other types of an interrupt
other than a hardware one. However, software interrupts got their name because mimic the hardware interrupts.
The "INT" instruction requests that the OS perform an action. The action that the OS takes will depend on what is placed in several of the CPU registers before the "INT"
instruction is executed. Often upon return from the requested action, a return value will be in the AX register and several flags will be set. The programmer will
have to check the values of the AX register and any flags to determine what instruction should be executed next.
There are many interrupts but the most common are those used for video (010h), DOS (021h), and the keyboard (016h). The following is a list of software interrupts and a brief description
BIOS Interrupts
00h - Divide by zero. An internal interrupt activated when there is an attempt to divide by zero
01h - Single Step. An internal interrupt that is activated by the CPU Trap flag is set. It is used for debuging purposes
02h - Nonmaskable. An internal interrupt that is activated when a memory error occurs
03h - Breakpoint. An internal interrupt that is activated when the 0CCh instruction is executed. It is used for debugging purposes
04h - Overflow. This interrupt is activated when the INTO instruction is executed and the Overflow flag is set
05h - Printscreen
06h - Illegal Instruction Error. This interrupt is activated when an invalid opcode is encountered
07h - Processor Extension Not Available. This interrupt is activated when the the math coprocessor is not present when trying to execute a coprocessor instruction
08h - Timer Tick. This interrupt is activated when the timer chip decrements an internal counter to zero
09h - Timer Interrupt. This interrupt is for updating the BIOS clock 18.2 times a second (see INT 01Ch)
0Ah - (Reserved)
0Bh - Secondary Communications Port. This interrupt is activated when a signal is recieved on communications port 2 (IRQ 3)
0Ch - Primary Communications Port. This interrupt is activated when a signal is recieved on communications port 1 (IRQ 4)
0Dh - (Reserved)
0Eh - Diskeette Interrupt. This interrupt is activated when a disk seek is in progress
10h - Video Services. This interrupt is activated when there is a manipulation to be performed on the video display.
11h - Equipment check. This interrupt returns a word indicating all of the peripherals attached to the system
12h - Memory Size. This interrupt returns the amount of memory in the AX register in the amount of 1024-byte blocks
13h - Floppy Disk Services. This interrupt is used for resetting the disk controller, to get the status of the most recent disk access, read and write physical sectors, and to format a disk
14h - Asynchronous (Serial) Port Services. This interrupt is for initializing, reading, writing, and returning the status of the communications port
15h - I/O Subsytem. This interrupt is used for accessing input and output devices
16h - Keyboard Services. This interrupt is for reading and inspectting the keyboard input
17h - Printer Services. This interrupt is for initializing, printing, and returning the status of the printer
18h - ROM BASIC. This interrupt is invoked when the system is turned on or restarted if attempts to read a boot sector from the fixed disk or floppy disk drives are unsuccessful
19h - Boot Strap. This interrupt is for rebooting DOS
1Ah - Time of Day. This interrupt is for getting the number of timer ticks since the machine was turned on or to set the counter to a new value (there are 18.2 ticks per second)
1Bh - Keyboard Break. This interrupt is executed by INT 9h when control-break is pressed on the keyboard
1Ch - User Timer Interrupt. This interrupt is an empty routine that is executed 18.2 time per second that can be substituted by a user program
1Dh - Video Parameters. This is a pointer to a table containing initialization and information for the video controller
1Eh - Diskette Parameters. This is a pointer to a table containing initialization and information for the diskette controller
1Fh - Graphics Table. This is a table kept in memory of all extended graphics characters with ASCII codes greather than 127
OS Interrupts
20h - Terminate Program. This interrupt will terminate a COM program (see INT 21h, function 4Ch)
21h - OS Services
22h - OS Terminate Address. This points to the addressof the parent program or process (this is the return address when the child program completes execution)
23h - OS Break Address. This is the address that the OS jumps to when control-break is pressed.
24h - OS Error Address. This is the OS
25h - OS Disk Read. This Interrupt is used for reading logical sectors from the disk
26h - OS Disk Write. This interrupt is used for writing logical sectorso on the disk
Misc.
27h - Terminate and Stay Resident (TSR). This interrupt performs a return to the OS or calling program; however, it leaves the the current program in memory.
28h-2Eh - (Reserved)
2Fh - Multiplex Interrupt. This interrupt allows for TSR programs to communicate with each other
30h-3Fh - (Reserved)
40h-41h - Fixed Disk Services. Fixed disk controller
42h-4Ch - (Reserved)
4Bh-7Fh - Interrupts available for application programs to use
80h-F0h - (Reserved)
F1h-FFh - Interrupts available for application programs to use
back to the top
- I don't understand where the registers come from and what their primary purpose is?
In the 16 bit Intel architecture there are 14 registers. All of these registers serve the purpose of storage allocated directly on the CPU and manipulation of data. Many CPU calculations are dependant on one or
more registers. The following registers are present in the Intel 16 bit architecture:
General purpose
Status and Control
|
|
Index
Segment
|
The 16 bit architecture has 4 general purpose registers: AX, BX, CX, DX. The AX register, named the accumulator, is favored by the CPU for arithmetic. The AX register is also favored because it is the fastest out of all of them.
The BX register, the base register, can be used to hold the address of a procedure or variable; however, BX is NOT the only register with this function (SI, DI, and BP also perform this function). The CX register, the counter register,
often performs the role of a counter for iterative structures and is often decremented automatically when a loop is executed. The DX register, or data register, is used in multiplication and division. This register stores the high 16 bits
of a multiplication result.
Each of the general purpose registers are broken into two, 8 bit (1 byte) parts: high, and low. The high or low parts of these registers can be access directly with an assembly command and can be manipulation without effecting the remainder of
of the register. Consider moving the value 010h into AX. When this is done with the command "MOV AX, 010H" AX now has the binary value "00000000 00001010." But lets suppose I want to stuff 010h into ah, I would use the following command "MOV AH, 010h"
The register would contain the following binary values "00001010 00000000." When I modify the higher or lower part of a register it does NOT effect the other half and will contain whatever value was previously stored in that half prior to a MOV instruction.
Likewise, the BX, CX, and DX registers act in the same manner.
The status and control flags are often used by programs and the OS to determine the result of instructions issued. The flags are as follows: overflow, direction, interrupt, trap, sign, zero, auxillary carry, parity, carry.
The flags are broken into two groups: control (direction, interrupt, trap), and status (carry, overflow, sign, zero, auxiliary carry, parity). The control flags can be used to control the CPU actions. Likewise, the status flags inidicate the status
of an executed instruction.
The IP (instruction pointer) registers contains the location of the next instruction to be executed.
The CS (code segment) register contains the start location of the code segment.
The DS (data segment) contains the address location of the data segment and hence the beginning address for all variables.
The SS (stack segment) contains the address location of the stack segment.
The ES (extra segment) serves the purpose of an extra storage location for a segment for variables
The BP (base pointer) the base pointer is the offset from the stack segment . It is used by routines to locate varaibles passed on the stack.
The SP (stack pointer) is the location of the top of stack from the stack segment.
The SI (source index) is used for string movement and manipulation. It is used to refer to the beginning of a string (pointing to that string) when that string is the source
The DI (destination index) is also use for string movement and manipulation. The DI register points to the destination of a string movement.
back to the top
- How do initialize the FPU?
Before you begin using the FPU, you should initialize it. You can do this by using the
FINIT or FNINIT command. The FINIT/FNINIT command initializes the coprocessor and resets all the registers and flags
to their default values. On the 80387/486, the condition codes of
the status word are cleared. On the 8087/287, they are unchanged.
This instruction has wait and no-wait versions. The wait version
(FINIT) checks for unmasked numeric errors; the no-wait version
(FNINIT) does not. When the .8087 directive is used, the assembler
puts the WAIT instruction before the wait versions and the NOP
instruction before the no-wait versions.
back to the top
- How can I store a floating point number into an integer?
FIST stores the value in ST to the specified memory location or
register. Temporary-real values in registers are converted to the
appropriate integer, BCD, or floating-point format as they are
stored. With FSTP, FISTP, and FBSTP, the ST register value is
popped off the stack.
Memory operands can be 32-, 64-, or 80-bit real numbers for FSTP,
or 16-, 32-, or 64-bit integers for FISTP.
back to the top
- How do I calculate the sine or cosine of a number without using some sort of lookup table?
To calculate sine or cosine, you can use FSIN or FCOS (respectively).
There is also a FSINCOS command.
FSIN replaces a value in radians in ST with its sine. FCOS
replaces a value in radians in ST with its cosine. FSINCOS
calculates the sine and cosine of a radian value in ST. The sine
replaces the value in ST, and then the cosine is pushed onto the
stack.
If |ST| < 2^63, the C2 bit of the status word is cleared and the
sine and/or cosine is calculated. Otherwise, C2 is set and no
calculation is performed. ST can be reduced to the required range
with FPREM or FPREM1.
back to the top
- How do I load an integer value onto the FPU stack
You can load an integer onto the FPU by using the FILD command, or FLD for a regular floating point value.
The FILD command pushes the specified operand onto the stack. All memory operands
are automatically converted to temporary-real numbers before being
loaded.Memory operands can be 32-, 64-, or 80-bit real numbers or 16-,
32-, or 64-bit integers.
back to the top
|
|
|
|