MP Final Record
MP Final Record
SYSTEM SPECIFICATION:
PROCESSORS:
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:
BUS: All address, data and control signals (ttl competitor) avoidable at edge connector as per
multi bus. The kit has own resident bus
POWER SUPPLY:5V, 2.5A for kit, +12, -12, 250mA for CRT +24/21V for EPROM
programmer.
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.
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?
3
3. Check the installation by typing “ml” in command prompt
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
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
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
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
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
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 ..
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
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 .............
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
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
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
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
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
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
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
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
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 .............
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
28
ADDITION OF 5-8BIT NUMBERS
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
30
SUBTRACTION OF 5-8BIT NUMBERS
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
32
MULTIPLICATION OF 5-8BIT NUMBERS
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
34
DIVISION OF 5-8BIT NUMBERS
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
36
1’s complement of a 8 bit 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 .õ ÿÿÿÿ....
.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
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µ.
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
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
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
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
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
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.
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.
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.
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.
µ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:
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.
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.
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
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
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