0% found this document useful (0 votes)
95 views58 pages

MP Final Record

The document describes an Intel 8086 microprocessor trainer kit. It includes an 8086 or 8088 CPU, 8087 numeric co-processor, 8089 I/O processor, and interfaces for memory, parallel and serial I/O, timers/counters, and a keyboard/display. The kit is used to study the 8086 architecture and train with assembly language programming.

Uploaded by

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

MP Final Record

The document describes an Intel 8086 microprocessor trainer kit. It includes an 8086 or 8088 CPU, 8087 numeric co-processor, 8089 I/O processor, and interfaces for memory, parallel and serial I/O, timers/counters, and a keyboard/display. The kit is used to study the 8086 architecture and train with assembly language programming.

Uploaded by

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

hi8086 MICROPROCESSOR

AIM: Study of Intel 8086 microprocessor trainer kit.

SYSTEM SPECIFICATION:

PROCESSORS:

CENTRAL PROCESSOR: 8086, 16 bit microprocessor operating in maximum mode or


8088 8bit microprocessor.

CO-PROCESSOR: 8087 Numeric Data processor.

INPUT/OUTPUT: 8089 I/O processor.

MEMORY:

EPROM: 16K bytes of EPROM loaded with monitor expandable to 1024 bytes using 27256.

RAM: 16K bytes of CMOS RAM expandable to 256K bytes using 6264/62256

INPUT/OUTPUT:

PARELLEL: 24 I/O lines expandable to 72 lines (3 numbers of 8255A).

SERIAL: E/A RS-232 C (main)

TIMER/COUNTER: Three16 bit timer/counter through 8253.

OTHER INTERFACES: EPROM programmer for 2763/27128/27256.

KEYBOARD DISPLAY:28 keys and 8 seven segment display.

BUS: All address, data and control signals (ttl competitor) avoidable at edge connector as per
multi bus. The kit has own resident bus

PHYSICAL SIZE: 9.5” X 12.5”

POWER SUPPLY:5V, 2.5A for kit, +12, -12, 250mA for CRT +24/21V for EPROM
programmer.

.OPERATING TEMPERATURE: 0 TO 50C.

CPU: 8086 is a 16 bit microprocessor and has 16 data lines and 20 address lines. The lower
16 address lines are multiplexed with 16 data lines. Hence it becomes necessary to latch the
address lines. This is done by using 74LS373. we have used this kit in maximum mode
(MN/MX input held logically low) NMI input is connected to VCT INT key.

1
CO-PROCESSOR 8087: The co-processor monitor instructions fetched by the host
processor and recognizes certain of these as its own executes them.

INPUT/OUTPUT PROCESSOR 8089: The 8086 and 8088 are designed to be used with
8089 in high performance input./output applications. 8089 resembles a microprocessor with
two DMA channels and an instruction set specifically tailored for input/output operations.
8089 can serve i/o device directly. In addition, it can transfer data from memory to memory
and from i/o to i/o device.

CLOCK GENERATIONS: The clock generation circuit in the Intel 8284 clock
generator/driver. The circuit accepts crystal input, which operates at the frequency of 14.7456
MHz the driver divides the crystal frequency by three to produce 4.9MHz clock signal
required by the CPU.

BUS CONTROLLER: 8288 is a bus controller which decodes status output by an 8089.
when the signal indicates that the processor is to run a bus cycle, 8288 issues a run command
that identifies a bus cycle as memory read, memory write, i/o read, i/o write e.t.c. it also
provides a signal that strobes the address into latches.

BUS ARBITERS: 8289 is a bus arbiter that controls the access of a processor to a multi
master system resource (typically memory) that is shared by two or more microprocessor
(master).

MEMORY: 16KB of EPROM and 16KB of CMOS RAM has been provided with 20-biit
address of 8086, a total of 1MB of memory can be addressed with the address slots as 00000
to FFFFF.

I/O DEVICES:

8279: 8279 is a general purpose programmable keyboard and display device designed for use
with 8086 microprocessor.
8255: 8255 is a programmable peripheral interface (PPI) designed use with 8086
microprocessor. This basically acts as a general purpose i/o component to interface
peripherals equipments to the system bus.

8253: This chip is a programmable interval timer/counter and can be used for the generation
of accurate time delay. It has got three independent 16 bit counters each having a count rate
of up to 2MHz.

8251: This chip is a programmable communication interface and is used as a peripheral


device. This device accepts data character from the CPU in parallel from and then converts
them into a continuous serial data stream from transmission simultaneously it can receive
data stream and convert them into parallel data for the stream and convert them into parallel
data for the CPU. It can also signal CPU whenever it can accept a new character for the
transmission or whenever it has received a character for the CPU.

DISPLAY: Eight digits of seven segment display has been provided on the trainer kit.

2
Introduction To MASM

MASM:
The Microsoft Macro Assembler (MASM) is an x86 assembler for MS-
DOS and Microsoft Windows. It supports a wide variety of macro facilities and
structured idioms, including high-level functions for looping and procedures. Later
versions added the capability of producing programs for Windows. MASM is one of
the few Microsoft development tools that target 16-bit, 32-bit and is supplied as a 64
bit version ML64.EXE for 64-bit platforms. Versions 5.0 and earlier were MS-
DOS applications. Versions 5.1 and 6.0 were available as both MS-
DOS and OS/2 applications. Versions 6.12 to 6.14 were implemented as patches for
version 6.11 which converted them from 16 bit MZ executables to 32 bit PE
executable files. All later versions have been 32 bit PE executable files built as Win32
console mode applications.
How to use MASM?

1.Open the command prompt window  (Start->Run->cmd)

2.    Set the path to the compiler. i.e. “;d:\masm\bin” by typing


“cd d:\masm\bin” as shown in figure below

3
3. Check the installation by typing “ml” in command prompt

If after typing “ml” the above message appears the masm is


properly installed and is working properly,now we proceed to
work a few microprocessors programmes using masm

4.    Now we can use almost any text editor to create an assembly


program. In this example, we will use Microsoft’s EDIT. Type
“edit example1.asm” on the command prompt and enter the
text of the program.

Save the file by “Alt-F”,”Alt+S”. Exit “Alt-F”,“Alt-X”

4
5.    Compile and link the assembly file by issuing “ml /Zi add8.asm”

6. Now the object file generated in the step five is converted using a
linker executable file , by typing the linker file in command prompt
i.e. “link16.exe” and in the proceeding steps you will be asked to
name your ‘.exe’ file
Let us name it executable file “add8.exe”.

5
7.    Now let’s start and configure the Code View debugger. Type
“cv example1.exe’ at the command prompt.

6
Now let us know what the code view debuuger mainly consist of

8.Now lets enter the input values for addition in “memory” window

The numbers highlighted in gray colour are inputs.

7
9. Now after entering the inputs press “F10” .The debugger will
execute each instruction as long as “F10” is pressed .Here the
pressing of “F10” should be stopped on the reaching of the halt
information
Note: During the execution process the change of status or
address variables of the registers can be easily seen.

Once the debugger reaches the halt instruction i.e. “hlt” the
programmer should stop pressing “F10” , i.e. Press “F10” until the
process terminates.And checks the output in the memory window.
The numbers highlighted in gray color IS OUTPUT

10. Once we obtain the required output come out of command


prompt by pressing “File->Exit”

Addition of two 8 bit numbers

8
Aim: - To write an assembly language program to add two 8 bit numbers.

Program:-

.model tiny
.stack 32h
.code
org 1000h
start:
mov si,0000h
mov al,[si]
inc si
mov bl,[si]
add al,bl
inc si
mov[si],al
hlt
end start

Codeview Output window

9
Source Code Registors
AX = 0098
0A05:1000 BE0000 MOV SI,0000 BX = 0042
0A05:1003 8A04 MOV AL,BYTE PTR [SI] CX = 0000
0A05:1005 46 INC SI DX = 0000
0A05:1006 8A1C MOV BL,BYTE PTR [SI] SP = 0032
0A05:1008 02C3 ADD AL,BL BP = 0000
0A05:100A 46 INC SI SI = 0002
0A05:100B 8804 MOV BYTE PTR [SI],AL DI = 0000
0A05:100D F4 HLT DS = 09F5
0A05:100E 0000 ADD BYTE PTR [BX+SI],AL ES = 09F5
0A05:1010 0000 ADD BYTE PTR [BX+SI],AL SS = 0B06
0A05:1012 0000 ADD BYTE PTR [BX+SI],AL CS = 0A05
0A05:1014 0000 ADD BYTE PTR [BX+SI],AL IP = 100D
0A05:1016 0000 ADD BYTE PTR [BX+SI],AL FL = 3202
0A05:1018 0000 ADD BYTE PTR [BX+SI],AL
0A05:101A 0000 ADD BYTE PTR [BX+SI],AL NV UP EI PL
0A05:101C 1101 ADC WORD PTR [BX+DI],AX NZ NA PO NC
0A05:101E 0000 ADD BYTE PTR [BX+SI],AL
0A05:1020 1101 ADC WORD PTR [BX+DI],AX
0A05:1022 0000 ADD BYTE PTR [BX+SI],AL
0A05:1024 1101 ADC WORD PTR [BX+DI],AX
0A05:1026 21821101 AND WORD PTR [BP+SI+0111],AX
0A05:102A 21821101 AND WORD PTR [BP+SI+0111],AX
0A05:102E 0000 ADD BYTE PTR [BX+SI],AL
0A05:1030 1101 ADC WORD PTR [BX+DI],AX
0A05:1032 0000 ADD BYTE PTR [BX+SI],AL
0A05:1034 1101 ADC WORD PTR [BX+DI],AX
0A05:1036 0000 ADD BYTE PTR [BX+SI],AL
0A05:1038 98 CBW
Memory(output)
09F5:0000 56 42 98 9F 00 9A F0 FE 1D F0 96 02 00 VB˜Ÿ.šðþð–.

09F5:000D 08 97 03 00 08 56 01 2D 04 AD 09 01 01 —.V -
09F5:001A 01 00 01 01 03 FF FF FF FF FF FF FF FF . ÿÿÿÿÿÿÿÿ
09F5:0027 FF FF FF FF FF BE 09 92 29 63 05 14 00 ÿÿÿÿÿ¾ ’)cµ.
09F5:0034 18 00 F5 09 FF FF FF FF 00 00 00 00 05 .õ ÿÿÿÿ....
09F5:0041 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:004E 00 00 CD 21 CB 00 00 00 00 00 00 00 00 ..Í!Ë........

10
Subtraction of two 8 bit numbers

Aim: - To write an assembly language program to subtract two 8 bit numbers.

Program:-

.model tiny
.stack 32h
.code
org 1000h
start:
mov si,0000h
mov al,[si]
inc si
mov bl,[si]
sub al,bl
inc si
mov[si],al
hlt
end start

11
Codeview Output window

Source Code Registors


0A05:1000 BE0000 MOV SI,0000 AX = 0014
0A05:1003 8A04 MOV AL,BYTE PTR [SI] BX = 0042
0A05:1005 46 INC SI CX = 0000
0A05:1006 8A1C MOV BL,BYTE PTR [SI] DX = 0000
0A05:1008 2AC3 SUB AL,BL SP = 0032
0A05:100A 46 INC SI BP = 0000
0A05:100B 8804 MOV BYTE PTR [SI],AL SI = 0002
0A05:100D F4 HLT DI = 0000
0A05:100E 0000 ADD BYTE PTR [BX+SI],AL DS = 09F5
0A05:1010 0000 ADD BYTE PTR [BX+SI],AL ES = 09F5
0A05:1012 0000 ADD BYTE PTR [BX+SI],AL SS = 0B06
0A05:1014 0000 ADD BYTE PTR [BX+SI],AL CS = 0A05
0A05:1016 0000 ADD BYTE PTR [BX+SI],AL IP = 100D
0A05:1018 0000 ADD BYTE PTR [BX+SI],AL FL = 3202
0A05:101A 0000 ADD BYTE PTR [BX+SI],AL
0A05:101C 1101 ADC WORD PTR [BX+DI],AX NV UP EI PL
0A05:101E 0000 ADD BYTE PTR [BX+SI],AL NZ NA PO NC
0A05:1020 1101 ADC WORD PTR [BX+DI],AX
0A05:1022 0000 ADD BYTE PTR [BX+SI],AL
0A05:1024 1101 ADC WORD PTR [BX+DI],AX
0A05:1026 21821101 AND WORD PTR [BP+SI+0111],AX
0A05:102A 21821101 AND WORD PTR [BP+SI+0111],AX
0A05:102E 0000 ADD BYTE PTR [BX+SI],AL
0A05:1030 1101 ADC WORD PTR [BX+DI],AX
0A05:1032 0000 ADD BYTE PTR [BX+SI],AL
0A05:1034 1101 ADC WORD PTR [BX+DI],AX
0A05:1036 0000 ADD BYTE PTR [BX+SI],AL
0A05:1038 0E PUSH CS
Memory
09F5:0000 56 42 14 9F 00 9A F0 FE 1D F0 96 02 00 VBµƒ.Ü≡■≡û.
09F5:000D 08 97 03 00 08 56 01 2D 04 AD 09 01 01 ù.V -¡

12
09F5:001A 01 00 01 01 FF FF FF FF FF FF FF FF FF .          
09F5:0027 FF FF FF FF FF BE 09 92 29 63 05 14 00      ╛Æ)cµ.
09F5:0034 18 00 F5 09 FF FF FF FF 00 00 00 00 05 .⌡     ....
09F5:0041 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:004E 00 00 CD 21 CB 00 00 00 00 00 00 00 00 ..═!╦........
09F5:005B 00 00 20 20 20 20 20 20 20 20 20 20 20 ..

Multiplication of two 8 bit numbers

Aim: - To write an assembly language program to multiply two 8 bit numbers.

Program
.model tiny
.stack 32h
.code
org 2000h
start:
mov si,0200h
mov al,[si]
inc si
mov bl,[si]
mul bl
inc si
mov [si],al
hlt
end start

13
Codeview Output window

Source Code Registors


0A05:2000 BE0002 MOV SI,0200 AX = 0200
0A05:2003 8A04 MOV AL,BYTE PTR [SI] BX = 0010
0A05:2005 46 INC SI CX = 0000
0A05:2006 8A1C MOV BL,BYTE PTR [SI] DX = 0000
0A05:2008 F6E3 MUL BL SP = 0032
0A05:200A 46 INC SI BP = 0000
0A05:200B 8804 MOV BYTE PTR [SI],AL SI = 0203
0A05:200D 46 INC SI DI = 0000
0A05:200E 8824 MOV BYTE PTR [SI],AH DS = 09F5
0A05:2010 F4 HLT ES = 09F5
0A05:2011 027203 ADD DH,BYTE PTR SS = 0C07
[BP+SI+03] CS = 0A05
0A05:2014 B80002 MOV AX,0200 IP = 2010
0A05:2017 8BC8 MOV CX,AX FL = 3207
0A05:2019 BAA00F MOV DX,0FA0
0A05:201C 8916AC12 MOV WORD PTR NV UP EI PL
[12AC],DX NZ NA PE CY
0A05:2020 8B1EA812 MOV BX,WORD PTR
[12A8]
0A05:2024 B43F MOV AH,3F
0A05:2026 CD21 INT 21
0A05:2028 5A POP DX
0A05:2029 5B POP BX
0A05:202A 7207 JB 2033
0A05:202C 3BC1 CMP AX,CX
0A05:202E 7503 JNZ 2033
0A05:2030 59 POP CX
0A05:2031 EB07 JMP 203A
0A05:2033 59 POP CX
0A05:2034 F9 STC
0A05:2035 B88D03 MOV AX,038D
0A05:2038 EB13 JMP 204D

14
Memory(output)
09F5:0200 20 10 00 02 00 00 00 00 00 00 00 00 00 ..........
09F5:020D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:021A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0227 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0234 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0241 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:024E 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

Division of two 8 bit numbers

Aim: - To write an assembly language program to divide two 8 bit numbers.

Program:-
.model tiny
.stack 32h
.code
org 2000h
start:
mov si,0200h
mov al,[si]
inc si
mov bl,[si]
div bl
inc si
mov [si],al
inc si
mov [si],ah
hlt
end start

15
Codeview Output window

Source Code Registors


AX = 0F01
0A05:2000 BE0002 MOV SI,0200 BX = 0011
0A05:2003 8A04 MOV AL,BYTE PTR [SI] CX = 0000
0A05:2005 46 INC SI DX = 0000
0A05:2006 8A1C MOV BL,BYTE PTR [SI] SP = 0032
0A05:2008 F6F3 DIV BL BP = 0000
0A05:200A 46 INC SI SI = 0203
0A05:200B 8804 MOV BYTE PTR [SI],AL DI = 0000
0A05:200D 46 INC SI DS = 09F5
0A05:200E 8824 MOV BYTE PTR [SI],AH ES = 09F5
0A05:2010 F4 HLT SS = 0C07
0A05:2011 027203 ADD DH,BYTE PTR CS = 0A05
[BP+SI+03] IP = 2010
0A05:2014 B80002 MOV AX,0200 FL = 3206
0A05:2017 8BC8 MOV CX,AX
0A05:2019 BAA00F MOV DX,0FA0 NV UP EI PL
0A05:201C 8916AC12 MOV WORD PTR NZ NA PE NC
[12AC],DX
0A05:2020 8B1EA812 MOV BX,WORD PTR
[12A8]
0A05:2024 B43F MOV AH,3F
0A05:2026 CD21 INT 21
0A05:2028 5A POP DX
0A05:2029 5B POP BX
0A05:202A 7207 JB 2033
0A05:202C 3BC1 CMP AX,CX
0A05:202E 7503 JNZ 2033
0A05:2030 59 POP CX
0A05:2031 EB07 JMP 203A
0A05:2033 59 POP CX
0A05:2034 0C00 OR AL,00
0A05:2036 0000 ADD BYTE PTR
[BX+SI],AL
0A05:2038 0002 ADD BYTE PTR
[BP+SI],AL

Memory(output)
09F5:0200 20 11 01 0F 00 00 00 00 00 00 00 00 00 ¤.........
09F5:020D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:021A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0227 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0234 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0241 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:024E 00 00 00 00 00 00 00 0000 00 00 00 00 .............

16
Addition of two 16 bit numbers

Aim: - To write an assembly language program to add two 16 bit numbers.

Program:-

.model tiny
.stack 32h
.code
org 4000h
start:
mov si,0400h
mov ax,[si]
inc si
inc si
mov bx,[si]
add ax,bx
inc si
inc si
mov[si],ax
hlt
end start

17
Codeview Output window

Source Code Registors


AX = E98C
0A05:4000 BE0004 MOV SI,0400 BX = 9298
0A05:4003 8B04 MOV AX,WORD PTR [SI] CX = 0000
0A05:4005 46 INC SI DX = 0000
0A05:4006 46 INC SI SP = 0032
0A05:4007 8B1C MOV BX,WORD PTR [SI] BP = 0000
0A05:4009 03C3 ADD AX,BX SI = 0404
0A05:400B 46 INC SI DI = 0000
0A05:400C 46 INC SI DS = 09F5
0A05:400D 8904 MOV WORD PTR [SI],AX ES = 09F5
0A05:400F F4 HLT SS = 0E06
0A05:4010 6F OUTSW CS = 0A05
0A05:4011 7420 JZ 4033 IP = 400F
0A05:4013 656E OUTSB FL = 3202
0A05:4015 6F OUTSW
0A05:4016 7567 JNZ 407F NV UP EI PL
0A05:4018 682063 PUSH 6320 NZ NA PO NC
0A05:401B 6F OUTSW
0A05:401C 6E OUTSB
0A05:401D 7665 JBE 4084
0A05:401F 6E OUTSB
0A05:4020 7469 JZ 408B
0A05:4022 6F OUTSW
0A05:4023 6E OUTSB
0A05:4024 61 POPA
0A05:4025 6C INSB
0A05:4026 206D65 AND BYTE PTR
[DI+65],CH
0A05:4029 6D INSW
0A05:402A 6F OUTSW
0A05:402B 7279 JB 40A6

Memory(output)
09F5:0400 F4 56 98 92 8C E9 00 00 00 00 00 00 00 ôV˜’Œé.......
09F5:040D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:041A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0427 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0434 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0441 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:044E 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

18
Subtraction of two 16 bit numbers

Aim: - To write an assembly language program to subtract two 16 bit numbers.

Program:-

.model tiny
.stack 32h
.code
org 4000h
start:
mov si,0400h
mov ax,[si]
inc si
inc si
mov bx,[si]
sub ax,bx
inc si
inc si
mov[si],ax
hlt
end start

19
Codeview Output window

Source Code Registors


AX = 1761
0A05:4000 BE0004 MOV SI,0400 BX = BC41
0A05:4003 8B04 MOV AX,WORD PTR [SI] CX = 0000
0A05:4005 46 INC SI DX = 0000
0A05:4006 46 INC SI SP = 0032
0A05:4007 8B1C MOV BX,WORD PTR [SI] BP = 0000
0A05:4009 2BC3 SUB AX,BX SI = 0404
0A05:400B 46 INC SI DI = 0000
0A05:400C 46 INC SI DS = 09F5
0A05:400D 8904 MOV WORD PTR [SI],AX ES = 09F5
0A05:400F F4 HLT SS = 0E06
0A05:4010 6F OUTSW CS = 0A05
0A05:4011 7420 JZ 4033 IP = 400F
0A05:4013 656E OUTSB FL = 3202
0A05:4015 6F OUTSW
0A05:4016 7567 JNZ 407F NV UP EI PL
0A05:4018 682063 PUSH 6320 NZ NA PO NC
0A05:401B 6F OUTSW
0A05:401C 6E OUTSB
0A05:401D 7665 JBE 4084
0A05:401F 6E OUTSB
0A05:4020 7469 JZ 408B
0A05:4022 6F OUTSW
0A05:4023 6E OUTSB
0A05:4024 61 POPA
0A05:4025 6C INSB
0A05:4026 206D65 AND BYTE PTR
[DI+65],CH
0A05:4029 6D INSW
0A05:402A 6F OUTSW
0A05:402B 7279 JB 40A6

Memory
09F5:0400 A2 D3 41 BC 61 17 00 00 00 00 00 00 00 ÓA¼a.......
09F5:040D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:041A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0427 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0434 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0441 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:044E 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

20
Multiplication of two 16 bit numbers

Aim: - To write an assembly language program to multiply two 16 bit numbers.

Program:-

.model tiny
.stack 32h
.code
org 4000h
start:
mov si,0400h
mov ax,[si]
inc si
inc si
mov bx,[si]
mul bx
inc si
inc si
mov[si],ax
inc si
inc si
mov[si],dx
hlt
end start

21
Codeview Output window

Source Code Registers


AX = 8B86
0A05:4000 BE0004 MOV SI,0400 BX = 30D3
0A05:4003 8B04 MOV AX,WORD PTR [SI] CX = 0000
0A05:4005 46 INC SI DX = 0080
0A05:4006 46 INC SI SP = 0032
0A05:4007 8B1C MOV BX,WORD PTR [SI] BP = 0000
0A05:4009 F7E3 MUL BX SI = 0406
0A05:400B 46 INC SI DI = 0000
0A05:400C 46 INC SI DS = 09F5
0A05:400D 8904 MOV WORD PTR [SI],AX ES = 09F5
0A05:400F 46 INC SI SS = 0E07
0A05:4010 46 INC SI CS = 0A05
0A05:4011 8914 MOV WORD PTR [SI],DX IP = 4013
0A05:4013 F4 HLT FL = 3207
0A05:4014 6E OUTSB
0A05:4015 6F OUTSW NV UP EI PL
0A05:4016 7567 JNZ 407F NZ NA PE CY
0A05:4018 682063 PUSH 6320
0A05:401B 6F OUTSW
0A05:401C 6E OUTSB
0A05:401D 7665 JBE 4084
0A05:401F 6E OUTSB
0A05:4020 7469 JZ 408B
0A05:4022 6F OUTSW
0A05:4023 6E OUTSB
0A05:4024 61 POPA
0A05:4025 6C INSB
0A05:4026 206D65 AND BYTE PTR
[DI+65],CH
0A05:4029 6D INSW
0A05:402A 6F OUTSW

Memory(output)
09F5:0400 A2 02 D3 30 86 8B 80 00 00 00 00 00 00¢Ó0†‹€......
09F5:040D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:041A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0427 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0434 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0441 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:044E 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

22
Division of two 16 bit numbers

Aim: - To write an assembly language program to Divide two 16 bit numbers.

Program:-

.model tiny
.stack 32h
.code
org 4000h
start:
mov si,0400h
mov ax,[si]
inc si
in si
mov bx,[si]
div bx
inc si
inc si
mov[si],ax
inc si
inc si
mov[si],dx
hlt
end start

23
Codeview Output window
Source Code Registers
0A05:4000 BE0004 MOV SI,0400 AX = 0006
0A05:4003 8B04 MOV AX,WORD PTR [SI] BX = 1234
0A05:4005 46 INC SI CX = 0000
0A05:4006 46 INC SI DX = 0B5C
0A05:4007 8B1C MOV BX,WORD PTR [SI] SP = 0032
0A05:4009 F7F3 DIV BX BP = 0000
0A05:400B 46 INC SI SI = 0406
0A05:400C 46 INC SI DI = 0000
0A05:400D 8904 MOV WORD PTR [SI],AX DS = 09F5
0A05:400F 46 INC SI ES = 09F5
0A05:4010 46 INC SI SS = 0E07
0A05:4011 8914 MOV WORD PTR [SI],DX CS = 0A05
0A05:4013 F4 HLT IP = 4013
0A05:4014 6E OUTSB FL = 3206
0A05:4015 6F OUTSW
0A05:4016 7567 JNZ 407F NV UP EI PL
0A05:4018 682063 PUSH 6320 NZ NA PE NC
0A05:401B 6F OUTSW
0A05:401C 6E OUTSB
0A05:401D 7665 JBE 4084
0A05:401F 6E OUTSB
0A05:4020 7469 JZ 408B
0A05:4022 6F OUTSW
0A05:4023 6E OUTSB
0A05:4024 61 POPA
0A05:4025 6C INSB
0A05:4026 206D65 AND BYTE PTR
[DI+65],CH
0A05:4029 6D INSW
0A05:402A 6F OUTSW

Memory(output)
09F5:0400 94 78 34 1 2 06 00 5C 0B 00 00 00 00 00 ”x4.\.....
09F5:040D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:041A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0427 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0434 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

24
Addition of two 8 bit BCD numbers

Aim: - To write an assembly language program to add two 8 bit BCD numbers.
Program:-
.model tiny
.stack 32h
.code
org 5000h
start:
mov si,0500h
mov al,[si]
inc si
mov bl,[si]
add al,bl
daa
inc si
mov[si],al
hlt
end start

25
Codeview Output window
Source Code Registers
0A05:5000 BE0005 MOV SI,0500 AX = 0050
0A05:5003 8A04 MOV AL,BYTE PTR [SI] BX = 0063
0A05:5005 46 INC SI CX = 0000
0A05:5006 8A1C MOV BL,BYTE PTR [SI] DX = 0000
0A05:5008 02C3 ADD AL,BL SP = 0032
0A05:500A 27 DAA BP = 0000
0A05:500B 46 INC SI SI = 0502
0A05:500C 8804 MOV BYTE PTR [SI],AL DI = 0000
0A05:500E F4 HLT DS = 09F5
0A05:500F 15795B ADC AX,5B79 ES = 09F5
0A05:5012 5E POP SI SS = 0F06
0A05:5013 C9 LEAVE CS = 0A05
0A05:5014 C20200 RET 0002 IP = 500E
0A05:5017 00558B ADD BYTE PTR [DI-75],DL FL = 3203
0A05:501A EC IN AL,DX
0A05:501B 57 PUSH DI NV UP EI PL
0A05:501C 56 PUSH SI NZ NA PO CY
0A05:501D 8B7606 MOV SI,WORD PTR [BP+06]
0A05:5020 8B7E04 MOV DI,WORD PTR [BP+04]
0A05:5023 F6441E02 TEST BYTE PTR [SI+1E],02
0A05:5027 7410 JZ 5039
0A05:5029 8BDE MOV BX,SI
0A05:502B E85805 CALL 5586
0A05:502E 80641EFD AND BYTE PTR [SI+1E],FD
0A05:5032 BF0100 MOV DI,0001
0A05:5035 56 PUSH SI
0A05:5036 E83F50 CALL A078
0A05:5039 00F5 ADD CH,DH
0A05:503B 090E5005 OR WORD PTR [0550],CX

Memory(output)
09F5:0500 87 63 50 00 00 00 00 00 00 00 00 00 00 ‡cP..........
09F5:050D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:051A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0527 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

26
09F5:0534 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

8-BIT ASCII ADDITION

AIM: To write an assembly language program for 8-bit ASCII addition.

Program:
.model tiny
.stack 32h
.code
org 5000h
start:
mov si,0500h
mov al,[si]
inc si
mov bl,[si]
add al,bl
aaa
inc si
mov [si],al
inc si
mov [si],ah
hlt
end start

27
Codeview Output window

Source Code Registers


0A05:5000 BE0005 MOV SI,0500 AX = 0106
0A05:5003 8A04 MOV AL,BYTE PTR [SI] BX = 0019
0A05:5005 46 INC SI CX = 0000
0A05:5006 8A1C MOV BL,BYTE PTR [SI] DX = 0000
0A05:5008 02C3 ADD AL,BL SP = 0032
0A05:500A 37 AAA BP = 0000
0A05:500B 46 INC SI SI = 0203
0A05:500C 8804 MOV BYTE PTR [SI],AL DI = 0000
0A05:500E 46 INC SI DS = 0B5F
0A05:500F 8824 MOV BYTE PTR [SI],AH ES = 0B5F
0A05:5011 F4 HLT SS = 0B71
0A05:5012 5E POP SI CS = 0B6F
0A05:5013 C9 LEAVE IP = 0011
0A05:5014 C20200 RET 0002 FL = 3207
0A05:5017 00558B ADD BYTE PTR [DI-75],DL
0A05:501A EC IN AL,DX NV UP EI PL
0A05:501B 57 PUSH DI NZ NA PE CY
0A05:501C 56 PUSH SI
0A05:501D 8B7606 MOV SI,WORD PTR [BP+06]
0A05:5020 8B7E04 MOV DI,WORD PTR [BP+04]
0A05:5023 F6441E02 TEST BYTE PTR [SI+1E],02
0A05:5027 7410 JZ 5039
0A05:5029 8BDE MOV BX,SI
0A05:502B E85805 CALL 5586
0A05:502E 80641EFD AND BYTE PTR [SI+1E],FD
0A05:5032 BF0100 MOV DI,0001
0A05:5035 56 PUSH SI
0A05:5036 E83F00 CALL 5078
0A05:5039 6A00 PUSH 00
Memory
09F5:0500 17 19 06 01 00 00 00 00 00 00 00 00 00 64. .........
09F5:050D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:051A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0527 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0534 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0541 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:054E 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

28
ADDITION OF 5-8BIT NUMBERS

AIM: To write an assembly language program to perform multibyte addition

PROGRAM:

.model tiny
.stack 32h
.code
org 2000h
start:
mov cx,04
mov si,02000h
mov al,[si]
inc si
add al,[si]
inc si
dec cx
jnz 0109
mov [si],al
hlt
end start

29
Codeview Output window

Source Code Registers


0A05:2000 BE0002 MOV SI,0200 AX = 000F
0A05:2003 8A04 MOV AL,BYTE PTR [SI] BX = 0000
0A05:2005 B104 MOV CL,04 CX = 0000
0A05:2007 024401 ADD AL,BYTE PTR [SI+01] DX = 0000
0A05:200A 46 INC SI SP = 0032
0A05:200B FEC9 DEC CL BP = 0000
0A05:200D 75F8 JNZ 2007 SI = 0204
0A05:200F 8804 MOV BYTE PTR [SI],AL DI = 0000
0A05:2011 F4 HLT DS = 09F5
0A05:2012 7203 JB 2017 ES = 09F5
0A05:2014 B80002 MOV AX,0200 SS = 0C07
0A05:2017 8BC8 MOV CX,AX CS = 0A05
0A05:2019 BAA00F MOV DX,0FA0 IP = 2011
0A05:201C 8916AC12 MOV WORD PTR [12AC],DX FL = 3246
0A05:2020 8B1EA812 MOV BX,WORD PTR [12A8]
0A05:2024 B43F MOV AH,3F NV UP EI PL
0A05:2026 CD21 INT 21 ZR NA PE NC
0A05:2028 5A POP DX
0A05:2029 5B POP BX
0A05:202A 7207 JB 2033
0A05:202C 3BC1 CMP AX,CX
Memory
09F5:0200 01 02 03 04 05 0F 00 00 00 00 00 00 00 ¤........
09F5:020D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:021A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0227 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0234 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0241 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:024E 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

30
SUBTRACTION OF 5-8BIT NUMBERS

AIM: To write an assembly language program to perform multibyte subtraction

PROGRAM:

.model tiny
.stack 32h
.code
org 2000h
start:
mov cx,04
mov si,02000h
mov al,[si]
inc si
sub al,[si]
inc si
dec cx
jnz 0109
mov [si],al
hlt
end start

31
Codeview Output window

Source Code Registers


0A05:2000 BE0002 MOV SI,0200 AX = 0000
0A05:2003 8A04 MOV AL,BYTE PTR [SI] BX = 0000
0A05:2005 B104 MOV CL,04 CX = 0000
0A05:2007 2A4401 SUB AL,BYTE PTR [SI+01] DX = 0000
0A05:200A 46 INC SI SP = 0032
0A05:200B FEC9 DEC CL BP = 0000
0A05:200D 75F8 JNZ 2007 SI = 0205
0A05:200F 46 INC SI DI = 0000
0A05:2010 8804 MOV BYTE PTR [SI],AL DS = 09F5
0A05:2012 F4 HLT ES = 09F5
0A05:2013 03B80002 ADD DI,WORD PTR SS = 0C07
[BX+SI+0200] CS = 0A05
0A05:2017 8BC8 MOV CX,AX IP = 2012
0A05:2019 BAA00F MOV DX,0FA0 FL = 3206
0A05:201C 8916AC12 MOV WORD PTR [12AC],DX
0A05:2020 8B1EA812 MOV BX,WORD PTR [12A8] NV UP EI PL
0A05:2024 B43F MOV AH,3F NZ NA PE NC
0A05:2026 CD21 INT 21
0A05:2028 5A POP DX
0A05:2029 5B POP BX
0A05:202A 7207 JB 2033
0A05:202C 3BC1 CMP AX,CX
0A05:202E 7503 JNZ 2033
0A05:2030 59 POP CX
0A05:2031 EB07 JMP 203A
0A05:2033 59 POP CX
0A05:2034 F9 STC
0A05:2035 B88D03 MOV AX,038D
0A05:2038 EB13 JMP 204D
0A05:203A 8B36AC12 MOV SI,WORD PTR [12AC]
Memory
09F5:0200 09 05 03 01 00 00 00 00 00 00 00 00 00 ý.......
09F5:020D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:021A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0227 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0234 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0241 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:024E 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

32
MULTIPLICATION OF 5-8BIT NUMBERS

AIM: To write an assembly language program to perform multibyte subtraction

PROGRAM:

.model tiny
.stack 32h
.code
org 2000h
start:
mov cx,04
mov si,02000h
mov al,[si]
inc si
mov bl,[si]
mul bl
inc si
dec cx
jnz 010b
mov [si],al
hlt
end start

33
Codeview Output window

Source Code Registers


AX = 000E
0A05:2000 BE0002 MOV SI,0200 BX = 0001
0A05:2003 8A04 MOV AL,BYTE PTR [SI] CX = 0000
0A05:2005 B104 MOV CL,04 DX = 0000
0A05:2007 8A5C01 MOV BL,BYTE PTR [SI+01] SP = 0032
0A05:200A F6E3 MUL BL BP = 0000
0A05:200C 46 INC SI SI = 0207
0A05:200D FEC9 DEC CL DI = 0000
0A05:200F 75F6 JNZ 2007 DS = 09F5
0A05:2011 46 INC SI ES = 09F5
0A05:2012 8904 MOV WORD PTR [SI],AX SS = 0C07
0A05:2014 46 INC SI CS = 0A05
0A05:2015 46 INC SI IP = 2018
0A05:2016 8914 MOV WORD PTR [SI],DX FL = 3203
0A05:2018 F4 HLT
0A05:2019 BAA00F MOV DX,0FA0 NV UP EI PL
0A05:201C 8916AC12 MOV WORD PTR [12AC],DX NZ NA PO CY
0A05:2020 8B1EA812 MOV BX,WORD PTR [12A8]
0A05:2024 B43F MOV AH,3F
0A05:2026 CD21 INT 21
0A05:2028 5A POP DX
0A05:2029 5B POP BX
0A05:202A 7207 JB 2033
0A05:202C 3BC1 CMP AX,CX
0A05:202E 7503 JNZ 2033
0A05:2030 59 POP CX
0A05:2031 EB07 JMP 203A
0A05:2033 59 POP CX
0A05:2034 F9 STC
0A05:2035 B88D03 MOV AX,038D
Memory
09F5:0200 01 01 01 01 01 01 0E 00 00 00 00 00 00 8......
09F5:020D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:021A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0227 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0234 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0241 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:024E 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

34
DIVISION OF 5-8BIT NUMBERS

AIM: To write an assembly language program to perform multibyte division

PROGRAM:

.model tiny
.stack 32h
.code
org 4000h
start:
mov cx,04
mov si,0200h
mov al,[si]
inc si
mov bl,[si]
div bl
inc si
dec cx
jnz 010b
mov [si],al
hlt
end start

35
Codeview Output window

Source Code Registers


AX = 0001
0A05:3FFE 0000 ADD BYTE PTR [BX+SI],AL BX = 0001
0A05:4000 BE0004 MOV SI,0400 CX = 0000
0A05:4003 8A04 MOV AL,BYTE PTR [SI] DX = 0000
0A05:4005 B104 MOV CL,04 SP = 0032
0A05:4007 8A5C01 MOV BL,BYTE PTR [SI+01] BP = 0000
0A05:400A F6F3 DIV BL SI = 0405
0A05:400C 46 INC SI DI = 0000
0A05:400D FEC9 DEC CL DS = 09F5
0A05:400F 75F6 JNZ 4007 ES = 09F5
0A05:4011 46 INC SI SS = 0E07
0A05:4012 8804 MOV BYTE PTR [SI],AL CS = 0A05
0A05:4014 F4 HLT IP = 4014
0A05:4015 6F OUTSW FL = 3206
0A05:4016 7567 JNZ 407F
0A05:4018 682063 PUSH 6320 NV UP EI PL
0A05:401B 6F OUTSW NZ NA PE NC
0A05:401C 6E OUTSB
0A05:401D 7665 JBE 4084
0A05:401F 6E OUTSB
0A05:4020 7469 JZ 408B
0A05:4022 6F OUTSW
0A05:4023 6E OUTSB
0A05:4024 61 POPA
0A05:4025 6C INSB
0A05:4026 206D65 AND BYTE PTR [DI+65],CH
0A05:4029 6D INSW
0A05:402A 6F OUTSW
0A05:402B 7279 JB 40A6
0A05:402D 206F6E AND BYTE PTR [BX+6E],CH
Memory
09F5:0400 08 02 02 02 01 01 00 00 00 00 00 00 00 @.......
09F5:040D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:041A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0427 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0434 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0441 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:044E 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

36
1’s complement of a 8 bit number

Aim: - To write an assembly language program to Find 1’s compliment of a


given number.

Program:-

.model tiny
.stack 32h
.code
org 1000h
start:
mov si,0000h
mov al,[si]
not al
inc si
mov[si],al
hlt
end start

37
Codeview Output window
Source Code Registors
0A05:1000 BE0000 MOV SI,0000 AX = 00ED
0A05:1003 8A04 MOV AL,BYTE PTR [SI] BX = 0000
0A05:1005 F6D0 NOT AL CX = 0000
0A05:1007 46 INC SI DX = 0000
0A05:1008 8804 MOV BYTE PTR [SI],AL SP = 0032
0A05:100A F4 HLT BP = 0000
0A05:100B 81000000 ADD WORD PTR [BX+SI],0000 SI = 0001
0A05:100F 0000 ADD BYTE PTR [BX+SI],AL DI = 0000
0A05:1011 0000 ADD BYTE PTR [BX+SI],AL DS = 0BF5
0A05:1013 0000 ADD BYTE PTR [BX+SI],AL ES = 0BF5
0A05:1015 0000 ADD BYTE PTR [BX+SI],AL SS = 0B70
0A05:1017 0000 ADD BYTE PTR [BX+SI],AL CS = 0B6F
0A05:1019 0000 ADD BYTE PTR [BX+SI],AL IP = 000A
0A05:101B 0011 ADD BYTE PTR [BX+DI],DL FL = 3202
0A05:101D 0100 ADD WORD PTR [BX+SI],AX
0A05:101F 0011 ADD BYTE PTR [BX+DI],DL NV UP EI PL
0A05:1021 0100 ADD WORD PTR [BX+SI],AX NZ NA PO NC
0A05:1023 0011 ADD BYTE PTR [BX+DI],DL
0A05:1025 0121 ADD WORD PTR [BX+DI],SP
0A05:1027 82 ???
0A05:1028 1101 ADC WORD PTR [BX+DI],AX
0A05:102A 21821101 AND WORD PTR [BP+SI+0111],AX
0A05:102E 0000 ADD BYTE PTR [BX+SI],AL
0A05:1030 1101 ADC WORD PTR [BX+DI],AX
0A05:1032 0000 ADD BYTE PTR [BX+SI],AL
0A05:1034 1101 ADC WORD PTR [BX+DI],AX
0A05:1036 0000 ADD BYTE PTR [BX+SI],AL
0A05:1038 52 PUSH DX
0A05:103A F5 CMC

Memory
09F5:0000 12 ED C1 E2 04 B7 92 B9 FF FF 2E A1 F6 RÿŸ.šðþð–.

38
09F5:000D 08 97 03 00 08 56 01 2D 04 AD 09 01 01 —.V -
09F5:001A 01 00 01 01 03 FF FF FF FF FF FF FF FF . ÿÿÿÿÿÿÿÿ
09F5:0027 FF FF FF FF FF BE 09 92 29 63 05 14 00 ÿÿÿÿÿ¾’)cµ.
09F5:0034 18 00 F5 09 FF FF FF FF 00 00 00 00 05 .õ ÿÿÿÿ....

2’s complement of a 8 bit number

Aim: - To write an assembly language program to Find 2’s compliment of a


given number.
Program:-

.model tiny
.stack 32h
.code
org 1000h
start:
mov si,0000h
mov al,[si]
neg al

39
inc si
mov[si],al
hlt
end start

Codeview Output window


Sorce code Registors
0A05:1000 BE0000 MOV SI,0000 AX = 00FD
0A05:1003 8A04 MOV AL,BYTE PTR [SI] BX = 0000
0A05:1005 F6D8 NEG AL CX = 0000
0A05:1007 46 INC SI DX = 0000
0A05:1008 8804 MOV BYTE PTR [SI],AL SP = 0032
0A05:100A F4 HLT BP = 0000
0A05:100B 81000000 ADD WORD PTR [BX+SI],0000 SI = 0001
0A05:100F 0000 ADD BYTE PTR [BX+SI],AL DI = 0000
0A05:1011 0000 ADD BYTE PTR [BX+SI],AL DS = 09F5
0A05:1013 0000 ADD BYTE PTR [BX+SI],AL ES = 09F5
0A05:1015 0000 ADD BYTE PTR [BX+SI],AL SS = 0B06
0A05:1017 0000 ADD BYTE PTR [BX+SI],AL CS = 0A05
0A05:1019 0000 ADD BYTE PTR [BX+SI],AL IP = 100A
0A05:101B 0011 ADD BYTE PTR [BX+DI],DL FL = 3203
0A05:101D 0100 ADD WORD PTR [BX+SI],AX
0A05:101F 0011 ADD BYTE PTR [BX+DI],DL NV UP EI PL
0A05:1021 0100 ADD WORD PTR [BX+SI],AX NZ NA PO CY

40
0A05:1023 0011 ADD BYTE PTR [BX+DI],DL
0A05:1025 0121 ADD WORD PTR [BX+DI],SP
0A05:1027 82 ???
0A05:1028 1101 ADC WORD PTR [BX+DI],AX
0A05:102A 21821101 AND WORD PTR
[BP+SI+0111],AX
0A05:102E 0000 ADD BYTE PTR [BX+SI],AL
0A05:1030 1101 ADC WORD PTR [BX+DI],AX
0A05:1032 0000 ADD BYTE PTR [BX+SI],AL
0A05:1034 1101 ADC WORD PTR [BX+DI],AX
0A05:1036 0000 ADD BYTE PTR [BX+SI],AL
0A05:1038 0300 ADD AX,WORD PTR [BX+SI]
0A05:103A F5 CMC

Memory
09F5:0000 03 FD C1 9F 00 9A F0 FE 1D F0 96 02 00 ýÿŸ.šðþð–.
09F5:000D 08 97 03 00 08 56 01 2D 04 AD 09 01 01 —.V -
09F5:001A 01 00 01 01 FF FF FF FF FF FF FF FF FF . ÿÿÿÿÿÿÿÿÿ
09F5:0027 FF FF FF FF FF BE 09 92 29 63 05 14 00 ÿÿÿÿÿ¾’)cµ.

Factorial of a given Number

Aim: - To write an assembly language program to Find Factorial of a given


Number.

41
Program:-
.model tiny
.stack 32h
.code
Org 0000h
Start:
MOV SI, 0600h
MOV AL, [SI]
MOV BL, AL
DEC BL
L1: MUL BL
DEC BL
JNZ L1
INC SI
MOV [SI], AL
HLT
end start

Codeview Output window


Source code Registors
0A05:6000 BE0006 MOV SI,0600 AX = 0078
0A05:6003 8A04 MOV AL,BYTE PTR [SI] BX = 0000
0A05:6005 8AD8 MOV BL,AL CX = 0000

42
0A05:6007 FECB DEC BL DX = 0000
0A05:6009 F6E3 MUL BL SP = 0032
0A05:600B FECB DEC BL BP = 0000
0A05:600D 75FA JNZ 6009 SI = 0601
0A05:600F 46 INC SI DI = 0000
0A05:6010 8804 MOV BYTE PTR [SI],AL DS = 09F5
0A05:6012 F4 HLT ES = 09F5
0A05:6013 46 INC SI SS = 1007
0A05:6014 06 PUSH ES CS = 0A05
0A05:6015 88471B MOV BYTE PTR [BX+1B],AL IP = 6012
0A05:6018 8B4604 MOV AX,WORD PTR [BP+04] FL = 3202
0A05:601B 89471C MOV WORD PTR [BX+1C],AX
0A05:601E 6A00 PUSH 00 NV UP EI
0A05:6020 6A00 PUSH 00 PL
0A05:6022 B80300 MOV AX,0003 NZ NA PO
0A05:6025 BA0100 MOV DX,0001 NC
0A05:6028 E8FFF1 CALL 522A
0A05:602B C9 LEAVE
0A05:602C C20600 RET 0006
0A05:602F 00558B ADD BYTE PTR [DI-75],DL
0A05:6032 EC IN AL,DX
0A05:6033 57 PUSH DI
0A05:6034 56 PUSH SI
0A05:6035 8B7606 MOV SI,WORD PTR [BP+06]
0A05:6038 2AE4 SUB AH,AH
0A05:603A 8A441B MOV AL,BYTE PTR [SI+1B]

Memory
09F5:0600 05 78 00 00 00 00 00 00 00 00 00 00 00 x...........
09F5:060D 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:061A 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0627 00 00 00 00 00 00 00 00 00 00 00 00 00 .............
09F5:0634 00 00 00 00 00 00 00 00 00 00 00 00 00 .............

43
8051
Micro Controller
programs

8051 microcontroller

Features & Applications

 It provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer, etc.)
in a single package

44
 8-bit data bus - It can access 8 bits of data in one operation (hence it is an 8-bit
microcontroller)
 16-bit address bus - It can access 216 memory locations - 64 kB each of RAM
and ROM
 On-chip RAM - 128 bytes ("Data Memory")
 On-chip ROM - 4 kB ("Program Memory")
 Four byte bi-directional input/output port
 UART (serial port)
 Two 16-bit Counter/timers
 Two-level interrupt priority
 Power saving mode

INTRODUCTION TO Keil µVision3 (µv3)

Software Development Cycle

 When you use the Keil µVision, the project development cycle is roughly the
same as it is for any other software development project.
 Create a project, select the target chip from the device database, and configure
the tool settings.
 Create source files in C or assembly.
 Build your application with the project manager.
 Correct errors in source files.
 Test the linked application.

µVision IDE

The µVision IDE combines project management, a rich-featured editor with


interactive error correction, option setup, make facility, and on-line help. Use
µVision to create your source files and organize them into a project that defines your
target application. µVision automatically compiles, assembles, and links your
embedded application and provides a single focal point for your development
efforts.

C51 Compiler & A51 Macro Assembler

Source files are created by the µVision IDE and are passed to the C51
Compiler or A51 Macro Assembler. The compiler and assembler process source files
and create relocatable object files. The Keil C51 Compiler is a full ANSI
implementation of the C programming language that supports all standard features
of the C language. In addition, numerous features for direct support of the 8051

45
architecture have been added. The Keil A51 macro assembler supports the complete
instruction set of the 8051 and all derivatives.

Start µVision

Create a Project File


To create a new project file select from the µVision menu: Project – New
Project- This opens a standard Windows dialog that asks you for the new project file
name. Use a separate folder for each project. µVision creates a new project file with
the name NAME.UV2 which contains a default target and file group name. You can
see these names in the Project Workspace – Files.

Select a Device

When you create a new project µVision asks you to select a CPU for your
project. The Select Device dialog box shows the µVision device database. Just select
the microcontroller you use. Example shows the AT89C51 controller. This selection
sets necessary tool options for the AT89C51 device and simplifies in this way the tool
configuration. When you create a new project, µVision may automatically add the
correct device specific CPU startup code for you.

Create New Source Files

46
You may create a new source file with the menu option File – New. This
opens an empty editor window where you can enter your source code. µVision
enables the C color syntax highlighting when you save your file with the dialog File
– Save As… under a filename with the extension *.asm. We are saving our example
file under the name MAIN.asm.

Once you have created your source file you can add this file to your project.
µVision offers several ways to add source files to a project. For example, you can
select the file group in the Project Workspace – Files page and click with the right
mouse key to open a local menu. The option Add Files opens the standard files
dialog. Select the file MAIN.asm you have just created.

Add and Configure the Startup Code

The STARTUP.A51 file is the startup code for the most 8051 CPU variants. The
startup code clears the data memory and initializes hardware and reentrant stack
pointers. In addition, some 8051 derivatives require a CPU initialization code that
needs to match the configuration of your hardware design.

Group Project Files

File group allow you to organize large projects. For the CPU startup code and other
system configuration files you may create a own file group in the Project –
Components, Environment, Books… dialog box. Use the New (Insert) button to
create a file group named System Files. In the project window you may drag and
drop the STARTUP.A51 file to this new file group.

47
Now, the Project Workspace – Files lists all items of your project.  To open a
file for editing, double click on the file name in the Project Workspace. You may
need to configure the startup STARTUP.A51 in the editor.

Set Tool Options for Target

µVision lets you set options for your target hardware. The dialog Options for Target
opens via the toolbar icon or via the Project - Options for Target menu item. In the
Target tab you specify all relevant parameters of your target hardware and the on-
chip components of the device you have selected. The following are the settings for
our example are shown.

48
The following table describes the options of the Target dialog:

Dialog Item Description


Xtal Specifies the CPU clock of your device. In most cases this value is identical
with the XTAL frequency.
Memory Model Specifies the C51 Compiler memory model. For starting new applications
the default SMALL is a good choice. Refer to "Memory Models and
Memory Types" section for a discussion of the various memory models.
Allocate Specifies the usage of the on-chip components that are typically enabled in
OnChip... the CPU startup code. If you are using on-chip xdata RAM (XRAM) you
Use multiple should also enable the XRAM access in the STARTUP.A51 file.
DPTR registers
Off- Here you specify all external memory areas of the target hardware.
chip...Memory
Code Banking Specifies the parameters for code and xdata banking. Refer to the "Code
Xdata Banking Banking" section for more information.

Build Project and Create a HEX File

49
Typical, the tool settings under Options – Target are all you need to start a new
application. You may translate all source files and line the application with a click on
the Build Target toolbar icon. When you build an application with syntax errors,
µVision will display errors and warning messages in the Output Window – Build
page. A double click on a message line opens the source file on the correct location in
a µVision editor window.

Once you have successfully generated your application you can start
debugging, now you may modify existing source code or add new source files to the
project. The Build Target toolbar button translates only modified or new source files
and generates the executable file. µVision maintains a file dependency list and
knows all include files used within a source file. Even the tool options are saved in
the file dependency list, so that µVision rebuilds files only when needed. With the
Rebuild Target command, all source files are translated, regardless of modifications.

After you have tested your application, it might be required to create an Intel
HEX file and to download the application software into the physical device using a
Flash programming utility. µVision creates HEX files with each build process when
Create HEX file under Options for Target – Output is enabled.

50
Overview of Options Dialogs

The Project - Options dialog pages let you set all the tool options. All options are
saved in the µVision project file Via the local menu in the Project Workspace – Files
you may set different options for a file group or even a single file. In this case you
may have an additional Properties page and only dialog pages that are related to the
selected item. 

The following table gives an overview of the various options dialogs. 

Dialog Description
Page
Target Specify the hardware of your application.
Output Define the output files of the tool chain and allows you to start user programs after
the build process.
Listing Specify all listing files generated by the tool chain.
C51, CX51 Set C51 Compiler specific tool options like code optimization or variable allocation.
A51, AX51 Set Assembler specific tool options like macro processing.
BL51 Define the location of memory classes and segments. Typical you will enable Use
Locate Memory Layout from Target Dialog as shown below to get automatic settings.
LX51 Locat
e
BL51 Misc Other linker related settings like Warning or memory Reserve directive.

51
LX51 Misc
Debug Settings for the µVision Debugger.
Properties File information and special options for files and groups.

Start Debug Mode


You start the debug mode of µVision with the Debug – Start/Stop Debug
Session command. Depending on the Options for Target – Debug configuration,
µVision will load the application program and run the startup code. µVision saves
the editor screen layout and restores the screen layout of the last debug session. If
the program execution stops, µVision opens an editor window with the source text
or shows CPU instructions in the disassembly window. The next executable
statement is marked with a yellow arrow.

Debug Windows and Dialogs


µVision provides several windows and dialogs that aid during the debugging
phase. The windows and dialogs open via toolbar buttons or the µVision menu.

Toolba Menu Item and Description


r
Debug — Breakpoint... (Ctrl+B): set, reviewed, or modified Access, Conditional, or
Execution breakpoints.
View — Code Coverage Window: statistics for code that has been executed.
View — Project Workspace — Regs Tab: show or modify CPU register contents.
View — Disassembly Window: assembly instructions or trace history intermixed with
source code.
View — Logic Analyzer Window: graphic display of variable or I/O changes.
View — Memory Window: review or modify memory contents.
  Debug — Memory Map...: specify memory areas for data and program code.
View — Output Window — Debug Tab: enter debug commands, expressions or invoke
debug functions.
View — Performance Analyzer Window: timing statistic of program execution.
View — Serial Window 1 - 3: terminal window for serial input/output.
  View — Symbol Window: list symbolic program information.
View — Toolbox: user-configurable buttons for quick command execution.
View — Watch & Call Stack Window: view and modify variables and lists function call
nesting.

AIM: To write a program for LED Blinking for LEDs those are connected to port-1

PROGRAM:

52
ORG 0000h
back : Mov a,#55h
Mov p1,a
Lcall delay
Mov a,#0AAh
Mov p1,a
Lcall delay
Sjmp back

Delay : Mov R5,#05h


Again :Djnz R5,Again
Ret
End

OUTPUT:

AIM: Write a program for 8051 Micro-Controller to Toggle all bits of port-P1

53
PROGRAM:

ORG 0000h
Back : Mov a,#0FFh
Mov p1,a
Lcall delay
Mov a,#0FEh
Mov p1,a
Lcall delay
Sjmp Back

Delay: Mov R5,#05h


Again: Djnz R5,Again
Ret
End

OUTPUT:

AIM: Write a program for 8051 Micro-Controller to get a byte of data from p0 and

54
Send it to p1

PROGRAM:

ORG 0000h
Mov R0,#55h
Mov P0,R0
Mov P1,P0
End

OUTPUT:

AIM: Write a program for 8051 Micro-Controller to transmit ‘A’ serially at 9600 baud rate

55
PROGRAM:

ORG 0000h
Mov TMOD, #20h
Mov SCON, #50h
Mov TH1, #-3h
Setb TR1
Again: Mov SBUF, #’A’
Here : Jnb TI,Here
clr TI
sjmp Again
end

OUTPUT:

AIM: Write a program for 8051 Micro-Controller to transmit ‘DVR’ serially at 4800

56
baud rate

PROGRAM:

ORG 000h
Mov TMOD,#20h
Mov SCON,#50h
Mov TH1,#-6h
Setb TR1
Again: Mov A,#'D'
Acall trans
Mov A,#'V'
Acall trans
Mov A,#'R'
Acall trans
Mov A,#' '
Acall trans
Sjmp Again
Trans : Mov Sbuf,A
Here : Jnb TI,Here
Clr TI
RET
End

OUTPUT:

AIM: Write a program for 8051 Micro-Controller to receive data serially at 9600 baud rate

57
PROGRAM:

ORG 000h
Mov TMOD,#20h
Mov SCON,#50h
Mov TH1,#-3h
Setb TR1
Here : Jnb Ri,Here
Mov A,Sbuf
Mov P1,A
Clr Ri
Sjmp Here
End

OUTPUT:

58

You might also like