Exp 2 - 201101
Exp 2 - 201101
Experiment 2
Familiarization with MASM, LINK and Assembler Editor
ID of Student: _______________________________
1.0 Objectives
Triebel W. A., Singh A., The 8088 and 8086 Microprocessors: Programming, Interfacing,
Software, Hardware, and Applications (4th Edition), Prentice Hall (2002).
Ytha Yu, Charles Marut, Assembly Language Programming and Organization Of the IBM PC.
1.3 Theory
The MASM assembler translates an assembly language source file into a machine language object file.
It generates three files, as shown in Figure 2.1.
Basic Microprocessor UCCE2043 Laboratory Experiment 2
Notepad
abc.ASM
Assembler
abc.LST
abc.OBJ
abc.CRF
Linker
abc.MAP
Figure 2.1
The List file shows all opcodes and offsets, and locations of errors.
The object file contains the machine language translation of the assembly source code, plus
other information needed to produce an executable file.
The cross reference file lists names used in the program and line numbers where they appear.
1.4 Procedure
2
Basic Microprocessor UCCE2043 Laboratory Experiment 2
.model small
.stack 100h
;--------------
.data
Values dw 234Dh, 1DE6h, 3BC7h ,566Ah
org 10h
total dw ?
;--------------
.code
main proc far
mov AX,data
mov DS,AX
mov CX,04 ;set up loop counter CX=4
mov DI,OFFSET Values ;set up data pointer DI
mov BX,00 ;initialize BX
C: add BX,[DI] ;add contents pointed at by [DI] to BX
inc DI ;increment DI twice
inc DI ;to point to next word
dec CX ;decrement loop counter
jnz C ;jump if loop counter not zero
mov SI,OFFSET total ;load pointer for sum
mov [SI],BX ;store in data segment
mov AH,4CH ;set up return
int 21H ;return to DOS
main endp
end main
Figure 2.2 – Refer for Figure 15 (Pg 12) for the program flow chart
/D<sym>[=<val>]
(2 marks)
/l[a]
(2 marks)
/c
(2 marks)
Table 2.1
4. In the same directory, when you type the command “masm” follow by
your saved file’s path and “add.asm /l”, you will encounter an
exchange similar to the Figure 2.3 if no error encounter.
Any error? ______________________. (2 marks)
[Total: 8 marks]
3
Basic Microprocessor UCCE2043 Laboratory Experiment 2
Assembling: c:\add.asm
Figure 2.3
The assembler does not create the list file automatically, so you must
type in an extra command (/l) for it. If there are any syntactic errors in
your code, the assembler reports it through severe errors and warnings.
The list file would help you pin down the location and the probable
cause of any such error. The list file also shows the actual machine code
generated by the assembler. If there are errors, fix them in the assembler
file and run the assembler again.
For the purposes of submission, print out the list file. (2 marks)
Note! You cannot use the label “C” in your program because “C” is reserved word in
MASM.
9. Invoke the linker by typing in following commands in Figure 2.4:
C:\masm\MASM613\BIN>link add
Figure 2.4
The linking process results in the creation of an executable file named
add.exe.
[Total: 8 marks]
4
Basic Microprocessor UCCE2043 Laboratory Experiment 2
_______ 10. Go to the directory where you have saved your file “add.asm”. In the
directory, type C:\masm\Irvine\ masm, you will encounter an exchange
similar to Figure 2.5.
11. Select “open” and click on the file “add.asm” on a correct directory
(You can type your program by select “new” on the menu)
12. Select Run ->Assemble. Refer to Figure 2.6
Assembling: F:\ADD.asm
Figure 2.6
5
Basic Microprocessor UCCE2043 Laboratory Experiment 2
Figure 2.7
14. After the above process the following files are created in your drive
__________________________________________________________ (2 marks)
__________________________________________________________ (2 marks)
6
Basic Microprocessor UCCE2043 Laboratory Experiment 2
Figure 2.9
7
Basic Microprocessor UCCE2043 Laboratory Experiment 2
19. Click Data->Add Watch and type in the word “total” and repeat the
steps with the word “DI”. You can see both words appear in the watch
window. This is shown in Figure 2.12
8
Basic Microprocessor UCCE2043 Laboratory Experiment 2
20 Press the F8 key to trace the program until the program ends. At what
address the result (total) store? ________________ (2 marks)
Refer to your source code, the result should store at location 10h.Is it
similar?
If no explain why?__________________________________________
____________________________________________ (2 marks)
22. What is the final result for “total” and “DI” in the watch window
before the following line appears on the screen “program terminated:
restart to continue”
[Total: 8 marks]
9
Basic Microprocessor UCCE2043 Laboratory Experiment 2
Run->Restart->Run->Animate,
______________________________________________________________ (2 marks)
_____________________________________________________________ (2 marks)
_____________________________________________________________ (2 marks)
24. A breakpoint is a special marker associated with a line of code that will
cause execution to halt and a special interactive mode to be entered
where variables can be examined, from which execution can be allowed
to continue.
Breakpoints are enabled by clicking Data->Set Breakpoint…->Break
This is shown in Figure 2.13
Breakpoints are removed with the Data->Edit Breakpoint… -
><Remove>->Ok. This is shown in Figure 2.14
[Total: 6 marks]
Basic Microprocessor UCCE2043 Laboratory Experiment 2
25. Restart the program. Let’s assume we wish to stop and examine memory
and the MPU registers just before the jnz instruction at line 22 is
executed.
26. Enable the breakpoint at line 22. The display is highlight with
________________ color. (2 marks)
The program now is ready to accept the first breakpoint address.
27. Depress the F5 key. Immediately the display will stop at line 22. Write
down the register that is highlighted and the value of the register.
________________________________________________________________________
______________________________________________________________ (2 marks)
29. What is the difference between breakpoint and Step (F10 key)?
__________________________________________________ (2 marks)
__________________________________________________________
[Total: 8 marks]
11
Basic Microprocessor UCCE2043 Laboratory Experiment 2
30. Write a program to find out the number of positive numbers and negative
numbers from the following data.
Start
Establish data
segment
No
All points
added? Test
Yes
Stop
12
Basic Microprocessor UCCE2043 Laboratory Experiment 2
(58 marks)
[Total:58 marks]
13