COE 205 Lab Manual Experiment N o 1 1 in
COE 205 Lab Manual Experiment N o 1 1 in
Experiment No 1
Introduction:
Objectives:
a. Edit
b. Assemble
c. Link
d. Execute
1.1.1 Assembling
The assembler is used to convert the assembly language instructions into machine
code. It is used immediately after writing the Assembly Language program. The
assembler starts by checking the syntax, or validity of the structure, of each
instruction in the source file. If any errors are found, the assembler displays a report
on these errors along with a brief explanation of their nature. However, if the program
does not contain any errors, the assembler produces an object file that has the same
name as the original file but with the “obj” extension.
1
COE 205 Lab Manual Experiment No 1
1.1.2 Linking
The linker is used to convert the object file to an executable file. The executable file is
the final set of machine code instructions that can directly be executed by the
microprocessor. It is different than the object file in the sense that it is self-contained
and re- locatable. An object file may represent one segment of a long program. This
segment can not operate by itself, and must be integrated with other object files
representing the rest of the program, in order to produce the final self-contained
executable file.
In addition to the executable file, the linker can also gene rate a special file called the
map file. This file contains information about the start, end, and the length of the
stack, code, and data segments. It also lists the entry point of the program.
1.1.3 Executing
The executable file contains the machine language code. It can be loaded in the RAM
and be executed by the microprocessor simply by typing, from the DOS prompt, the
name of the file followed by the Carriage Return Key (Enter Key). If the program
produces an output on the screen, or a sequence of control signals to control a piece of
hardware, the effect should be noticed almost instantly. However, if the program
manipulates data in memory, nothing would seem to have happened as a result of
executing the program.
The assembler being used in this lab is called MS-MASM. MASM is an interactive
means for assembling linking and debugging assembly language programs.
Microsoft’s Macro Assembler (MASM) is an integrated software package written by
Microsoft Corporation for professional software developers. It consists of an editor,
an assembler, a linker and a debugger (CodeView). The programmer’s workbench
(PWB) combines these four parts into a user- friendly programming environment with
built- in on- line help.
The following table summarizes all the steps and commands used to edit, assemble
link and run a program using MASM.
2
COE 205 Lab Manual Experiment No 1
1.2.1 MS-PWB:
The PWB is an environment that allows the user to define a project that may contain
one or more files. Then, the user may select all the necessary assembling, linking, and
debugging options for that project. Once these options are set, the user need not set
them again for that project. The PWB allows the user to edit, assemble, run, or debug
his program without leaving the PWB environment. It also allows the user to get help
on any keyword by pointing to the keyword and pressing the F1 key.
1.3 CodeView
The CodeView (CV) is a useful utility that allows program tracing and monitoring the
processor status while running a program. In this section we are going to learn how to
use MASM and code view.
Before you start the steps below, write the program that appears in Figure 1.1 using a
text editor and save it as prog1.asm in the directory you created in the last lab.
After the program is saved, assemble it then link it. You should get and *.exe file in
your directory.
To assemble the program, at the DOS prompt type:
3
COE 205 Lab Manual Experiment No 1
A prog1.obj file is now created. Link your program now, the following appears on
the screen.
A prog1.exe file is now created. Notice, that because a name was given in front of the
map file, a prog1.map file has also been created.
The Map file contains useful information about the executable program, the prog1.exe
file. More details will be given concerning the MAP file in the coming labs.
You can run your program by typing the following at the DOS prompt:
Since the program does not give any output, nothing is displayed on the screen. To
debug our program and see its effect while running, another tool is used, the code
view.
4
COE 205 Lab Manual Experiment No 1
1. From the start menu, select Programs> Masm 611> Masm Prompt. You will
get to the DOS screen.
2. Change the directory to the directory where your program resides
Z:\> cd COE205\LAB2\
3. Use the following command to run code view: cv prog1.exe then press
Enter.
4. You will get the following screen (Figure 1.2).
The first two columns in the CV window show the address of each instruction of the
program. The address is divided into two parts, a segment number and an offset. The
whole address has the following format:
The segment number in this case represents the code segment (CS).
The instructio n
is saved in the code segment number 0A24 at offset, or address, 0009. The offset
indicates a specific location within the segment.
5
COE 205 Lab Manual Experiment No 1
Memory is divided into segments of size 64KByte each. Therefore, the number of bits
required to address any location in memory is 16-bit (2 bytes).
The above instruction starts at address 0A24:0009 and occupies 3 bytes. Hence, it
ends at address 0A24:000B. The following instruction starts at address 0A24:000C.
All the instructions of a program are within the same segment.
The next column shows the machine code of each instruction. This is how the
effectively instructions are saved inside the system memory. Generally, the first few
bits or byte of the instruction correspond to the opcode, which indicates the operation
type (e.g. MOV, ADD) and the addressing mode.
Example:
Since both instructions have the effect of moving an immediate value into a word
register, the high bytes in both instructions are identical (B8). The lower bytes carry
the value to be loaded into the register. Notice that the values to be moved are written
in reverse order.
Different instructions may have different lengths. To see that, compare the following
two instructions.
The last column on the main window shows the assembly language program source.
Each instruction appears on one line. The instruction that is black-highlighted is the
instruction that is going to be executed next. In figure 1.1 the instruction “MOV AX,
07D0” is the next instruction to be executed.
Recall from the first experiment, that an assembly language instruction may have
zero, one or two operands. In case of a two-operand instruction, the right-hand
operand is the source and the left- hand operand is the destination. In the instruction
6
COE 205 Lab Manual Experiment No 1
The registers window may be viewed from the option Windows and Registers, or by
simultaneously clicking the keys Alt and 7. This window shows the current values of
the 14 internal registers. The default view is the 16-bit option for the 8086. To switch
to the 32-bit register view, click the Options menu and select the 32-bit Registers
option.
The lower part of the window contains the flags that indicate the status of the CPU
after executing the last instruction. They are arranged as shown in Fig 6.
Value
Flag
0 1
7
COE 205 Lab Manual Experiment No 1
The whole program may be run as a whole by pressing F5 (the option GO). However,
the program should have a sequence of instructions to force it to stop, such as the one
shown below, or a breakpoint (next section) inserted at a given instruction to force
the program halt execution.
In order to run the program step by step both keys F8 and F10 may be used. To
execute the next instruction press F8 or F10. The cursor will move one position down.
Any change in register content is highlighted on the register window.
In the program above, the first instruction moves the value 07D0 h into the register
AX. After executing this instruction, the value of AX, initially equal to 0000h will
change to 07D0h. It can be noticed that any value that changes is highlighted. After
executing the previous instruction, notice that besides AX other registers have also
been highlighted, namely IP and FL.
1.4.3 Breakpoints
1. Move the mouse at the point where you the breakpoint is to be inserted
2. From the Data menu select Set Breakpoint
3. or double click the instruction that you would like to stop at
4. Press F5 to run the program until the breakpoint
8
COE 205 Lab Manual Experiment No 1
1.6.2 Part I
9
COE 205 Lab Manual Experiment No 1
___________________________________________________________________
MOV AX, 00
MOV BX, MULT1
MOV CX, MULT2
MULT: ADD AX, BX
DEC CX
JNZ MULT
MOV DX, AX
10