0% found this document useful (0 votes)
9 views

Exp 2 - 201101

Basic Microprocessor

Uploaded by

marxx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Exp 2 - 201101

Basic Microprocessor

Uploaded by

marxx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Basic Microprocessor UCCE2043 Laboratory Experiment 2

Experiment 2
Familiarization with MASM, LINK and Assembler Editor

Name of Student: _____________________________ Date: _____________

ID of Student: _______________________________

1.0 Objectives

• To assemble, link, download, and run machine-language programs


• To use MASM to assemble a source program into object and run modules.
• To identify and correct syntax errors in a source program
• To use Assembler Editor to ease up the debug process
• To write some simple 8086/8088 assembly language programs

1.1 Material Requirements

A computer with MASM and Assembler Editor.


8088/86 instruction set

1.2 Reference Textbook

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

Refer to lecture note Chapter 3 titled “Arts of 80x86 programming”.

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

abc.EXE Converter—hex2bin abc.BIN

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

Check Step Procedure

1. Insert the Handy drive/ Diskette into USB socket/ drive A.

2. Using a text editor, such as MS-DOS EDIT or Windows Notepad, create


a new file called add.asm and enter the codes shown in Figure 2.2 into
that file.

Before proceeding further, notice a few important points in the above


code. Microsoft assembler requires that you include these first three lines
and the last two lines in any 8086/8088 assembler program for successful
assembly. There are several possible variations of these assembler
directives, but they are not important for these simple programs. The
TITLE of the program can be anything that you choose. There should be
a label at the beginning of the assembler code (main proc), and this label
should be specified after the last END.

3. Save your file as add.asm in your own disk or handy drive.

2
Basic Microprocessor UCCE2043 Laboratory Experiment 2

title Adds four words of data and saves the result

.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

Check Step Procedure

3. In the directory C:\MASM\MASM613\BIN, type “masm/?”and fill in


the Table 2.1.
Command Functions

/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

C:\masm\MASM613\BIN> masm a:\add.asm /l


Microsoft (R) MASM Compatibility Driver
Copyright (C) Microsoft Corp 1993. All rights reserved.

Invoking: ML.EXE /I. /Zm /c /Ta c:\add.asm

Microsoft (R) Macro Assembler Version 6.13.7299


Copyright (C) Microsoft Corp 1981-1997. All rights reserved.

Assembling: c:\add.asm

Figure 2.3

Check Step Procedure

5. How many warning errors are reported?_________________. (2 marks)

6. Use an editor to view the source listing in the file add.lst.

7. Correct the errors in add.asm. Corrections data==>@data, 4CHI==>


4CH, C:==>Again, jnz C ==> jnz Again (2 marks)

8. Repeat Steps 4. What files are created if no errors occur?


_________________________________________________(2 marks)

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

Microsoft (R) Segmented Executable Linker Version 5.31.009 Jul 13 1992


Copyright (C) Microsoft Corp 1984-1992. All rights reserved.

Run File [add.exe]:


List File [nul.map]:
Libraries [.lib]:
Definitions File [nul.def]:
C:\masm\MASM613\BIN>

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

Check Step Procedure

_______ 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.

Figure 2.5 Assembler Editor

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

Microsoft (R) MASM Compatibility Driver


Copyright (C) Microsoft Corp 1993. All rights reserved.

Invoking: ML.EXE /I. /Zm /c /Zi F:\ADD.asm

Microsoft (R) Macro Assembler Version 6.13.7299


Copyright (C) Microsoft Corp 1981-1997. All rights reserved.

Assembling: F:\ADD.asm

Press any key to continue...

Figure 2.6

13. Select Run->Link. Figure 2.7.

5
Basic Microprocessor UCCE2043 Laboratory Experiment 2

Microsoft (R) Segmented Executable Linker Version 5.31.009 Jul 13


1992
Copyright (C) Microsoft Corp 1984-1992. All rights reserved.

Definitions File [nul.def]:


Microsoft Debugging Information Compactor Version 4.01.00
Copyright(c) 1987-1992 Microsoft Corporation

Line/Address size = 136


Public symbol size = 0
Initial symbol size = 162
Final symbol size = 180
Global symbol size = 0
Initial type size = 28
Compacted type size = 36

Press any key to continue...

Figure 2.7

Check Step Procedure

14. After the above process the following files are created in your drive

__________________________________________________________ (2 marks)

15. List file can be created by selecting


Run->Set pathnames ->Assembler command line -> Options->
and include the following lines /z/zi/l

16. Click Run->Debug. Refer to Figure 2.8

17. Press F6. What is the function of this key?

__________________________________________________________ (2 marks)

18. Perform the following steps:


Click Windows->Register,
Windows->Memory1,
Windows->Source1.
Windows->Watch
The location of above windows can arrange by using Windows->Move and Windows-
>Size on the menu bar. The layout is shown in Figure 2.9
(Memory and source windows can be change by clicking Options as shown in Figure
2.10 and Figure 2.11)
[Total: 4 marks]

6
Basic Microprocessor UCCE2043 Laboratory Experiment 2

Figure 2.8 Code View

Figure 2.9

Watch windows Registers


Source code listing Data Segment memory

7
Basic Microprocessor UCCE2043 Laboratory Experiment 2

Figure 2.10 Memory Window Options

Figure 2.11 Source Window Options

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

Figure 2.12 Watch Window Watch window

Check Step Procedure

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)

21. You can always restart the process by clicking Run->Restart.

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: _________________ DI:__________________ (4 marks)

[Total: 8 marks]
9
Basic Microprocessor UCCE2043 Laboratory Experiment 2

Check Step Procedure

23. Explain the function of the following process:

Run->Restart->Run->Animate,

______________________________________________________________ (2 marks)

Run->Restart->F5 key (continue until the program terminated)

_____________________________________________________________ (2 marks)

Run->Restart->F10 key(continue until the program terminated)

_____________________________________________________________ (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

Figure 2.13 Set Breakpoint Window

[Total: 6 marks]
Basic Microprocessor UCCE2043 Laboratory Experiment 2

Figure 2.14 Edit Breakpoint Windows

Check Step Procedure

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)

28. The loop will be repeated ______________times. On the


__________pass, the program will escape the loop. For every loop,
monitor the changes 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.

VALUES DW 2579H, 0A500H, 0C009H,0159H,0B900H.


(Hint: use SHL, JC, JNZ)
For the purposes of submission, print out the list file and demo to
your lecturer.

Start

Establish data
segment

Set counter for the


number of points Initialization

Set the initial sum

Obtain the next data


point

Prepare for next


Sign extend the data point additon
point

Add the point to the


sum Perform addtion

Update the counter Update pointer


for the next point Initialization
and counter

No
All points
added? Test

Yes

Stop

Figure 15: Flow chart For Program Figure 2.2

12
Basic Microprocessor UCCE2043 Laboratory Experiment 2

(58 marks)

[Total:58 marks]
13

You might also like