0% found this document useful (0 votes)
47 views17 pages

MC Manual Updated

Contains control system assignment

Uploaded by

vanizeh54
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)
47 views17 pages

MC Manual Updated

Contains control system assignment

Uploaded by

vanizeh54
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/ 17

8051 Microcontroller

Steps to run a assembly language code in Kiel

1. Double click on the Icon Kiel Vision.


2. Select Project tab, under that option New Vision Project.
3. A window opens to create a project. Create a folder and save by giving a file name to
the project.
4. A window opens to select the device. Select AT89C51 from the list of devices and
say OK.
5. Select File tab, under that new that opens a window where you can type the code and
save.
6. On the left palette, under the source group option, right click, add existing files to
source group. Select the file to be added to the source group.
7. Select Debug tab, under that option, start/stop debug option, the code is ready to be
executed.
8. To provide data in the memory, Select View tab, Select memory window, you can
select any memory location by typing the required address.
i. Internal RAM:I:0x20
ii. External Ram: X:0x20
9. After providing the input data, Select Debug Tab, Option Run and verify the results.
I. ASSEMBLY LANGUAGE PROGRAMS

DATA TRANSFER PROGRAMS


1. Write an ALP to move a block of n bytes of data from source (20h) to destination (40h) using
Internal-RAM. org 0h
Org 0h
mov r0,#20h
mov r1,#40h
mov r2,#05h
rep :mov a,@r0
mov @r1,a
inc r0
inc r1
djnz r2,rep
end

Before Execution:

Registers: r0=20h, r1=40h,r2=05h

20: 11 22 33 44 55 66 77
40: 00 00 00 00 00 00 00

After Execution:

20: 11 22 33 44 55 66 77
40: 11 22 33 44 55 00 00

Registers: r0=25h, r1=45h,r2=00h

Memory Window after Execution:


2. Write an ALP to move a block of n bytes of data from source (2000h) to destination (2050h) using
External RAM.

org 0000h
mov dptr,#2000h
mov r0,#50h
mov r1,#20h
mov r2,#05h
rep:movx a,@dptr
push dph
push dpl
mov dph,r1
mov dpl,r0
movx @dptr,a
inc dptr
mov r1,dph
mov r0,dpl
pop dpl
pop dph
inc dptr
djnz r2,rep
end

Before Execution:

Registers: r0=50h, r0=20h,r2=05h,dptr=2000h

X:2000: 11 22 33 44 55 66 77
X:2050: 00 00 00 00 00 00 00

After Execution:

X:2000: 11 22 33 44 55 66 77
X:2050: 11 22 33 44 55 00 00

Registers: r0=55h, r1=20h,r2=00h, dptr=2005h

Memory Window after Execution:


3. Write an ALP To exchange the source block starting with address 20h, (Internal RAM)
containing N (05) bytes of data with destination block starting with address 40h (Internal RAM).
Org 0h
mov r0,#20h
mov r1,#40h
mov r2,#05h
repeat: mov a,@r0
xch a,@r1
mov @r0,a
inc r0
inc r1
djnz r2,repeat
end

Before Execution:

Registers: r0=20h, r1=40h, r2=05h


20: 11 22 33 44 55
40: 10 20 30 40 50

After Execution:
Registers: r0=45h, r1=55h, r2=00h

20: 10 20 30 40 50
40: 11 22 33 44 55

Memory Window after Execution:


4. Write an ALP to exchange the source block starting with address 10h (Internal memory),
containing n (06) bytes of data with destination block starting at location 00h (External memory).

Org 0000h
mov r0,#10h
mov dptr,#0000h
mov r2,#06h
repeat: movx a,@dptr
xch a,@r0
movx @dptr,a
inc r0
inc dptr
djnz r2,repeat
end

Before Execution:

Registers: r0=10h, r2=06h,dptr=0000h


I:10: 11 22 33 44 55
X:0000: 10 20 30 40 50

After Execution:
Registers: r0=16h, r2=00h, dptr=0006h
I:10: 10 20 30 40 50
X:0000: 11 22 33 44 55

Memory Window after Execution:


Arithmetic & Logical Operation Programs:
5. Write an ALP to add the byte in the RAM at 34h and 35h, store the result in the register R5
(LSB) and R6 (MSB), using Indirect Addressing Mode.

org 0h
mov r0,#34h // Number 1
mov r1,#35h // Number 2
clr c
mov a,@r0
mov r2,a
mov a,@r1
add a,r2
mov r5,a
clr a
addc a,#00h
mov r6,a
end

Before Execution

R0 R1 R5 R6
34 35 xx xx

After Execution
R0 R1 R5 R6
34 35 69 00

Memory and Register Window after Execution:


6. Write an ALP to subtract the bytes in Internal RAM 34h &35h store the result in register R5
(LSB) & R6 (MSB).

org 0h
mov r0,#34h // Number 1
mov r1,#35h // Number 2
clr c
mov a,@r0
mov r2,a
mov a,@r1
subb a,r2
mov r5,a
clr a
addc a,#00h
mov r6,a
end

Before Execution

R0 R1 R5 R6
34 35 xx xx

After Execution
R0 R1 R5 R6
34 35 69 00

Memory and Register Window after Execution:


7. Write an ALP to multiply two 8-bit numbers stored at 30h and 31h and store16- bit
result in 32h and 33h of Internal RAM.

org 0h
mov a,30h
mov b,31h
mul ab
mov 32h,a
mov 33h,b
end

Output:

Before Execution:
30h: 05 06 00 00

After Execution:
30: 05 06 1E 00

Memory Window after Execution:


8. Write an ALP to perform division operation on 8-bit number by 8-bit
number.

org 0h
mov r2,#0fh
mov r3,#05h
mov a,r3
cjne a,#00h,proceed
sjmp last
proceed: mov a,r2
mov b,r3
div ab
mov r4,a
mov r5,b
last: lcall 0003h
end

Before Execution:
R2= 0f,r3=05,r4=xx,r5=xx

After Execution:
R2= 0f, r3=05, r4=05,r5=00
Register Window after Execution:
9. Write an ALP to separate positive and negative in a given array.
org 0h
mov r0,#30h
mov r1,#40h
mov r2,#05h
mov b,r2
rep: mov a,@r0
jb acc.7,skip
mov @r1,a
inc r1
skip: inc r0
djnz r2,rep
mov r1,#50h
mov r0,#30h
rep1: mov a,@r0
jnb acc.7,skip1
mov @r1,a
inc r1
skip1: inc r0
djnz b,rep1
sjmp $
end

Before Execution: After Execution:

30h: 56 89 9A 22 11 30h: 56 89 9A 22 11
40h: 00 00 00 00 00 40h: 56 22 11 00 00
50h: 00 00 00 00 00 50h: 89 9A 00 00 00

Memory Window after Execution


10.Write an ALP to separate odd and even numbers in a given array.
org 0h
mov r0,#30h
mov r1,#40h
mov r2,#05h
mov b,r2
rep: mov a,@r0
jb acc.0,skip
mov @r1,a
inc r1
skip: inc r0
djnz r2,rep
mov r1,#50h
mov r0,#30h
rep1: mov a,@r0
jnb acc.0,skip1
mov @r1,a
inc r1
skip1: inc r0
djnz b,rep1
sjmp $
end

Before Execution: After Execution:

30h: 56 89 9A 22 11 30h: 56 89 9A 22 11
40h: 00 00 00 00 00 40h: 56 9A 22 00 00
50h: 00 00 00 00 00 50h: 89 11 00 00 00

Memory Window after Execution:


11. Write an ALP to arrange the numbers in Ascending & Descending order.
org 0h
mov b,#5h
dec b
oloop: mov r2,b
mov r0,#30h
mov r1,#30h
inc r1
iloop: mov 40h,@r0
mov a,@r1
cjne a,40h, nequal
sjmp skip
nequal: jnc skip //replace with jc for descending order
xch a,@r0
mov @r1,a
skip: inc r0
inc r1
djnz r2,iloop
djnz b,oloop
end

Before Execution:
30: 11 06 05 23 54

After Execution:

i. Ascending Order: ii. Ascending Order:

30: 05 06 11 23 54 30: 54 23 11 06 05

Memory Window after Execution:


12. Write an ALP to find Largest & Smallest number from a given array
starting from 20h & store it in Internal Memory location 40h.
org 0h
mov r0,#20h
mov r2,#5h
dec r2
mov 40h,@r0
rep:inc r0
mov a,@r0
cjne a,40h,next
sjmp skip
next:jc skip //replace by jnc for smallest
mov 40h,a
skip:djnz r2,rep

end

Before Execution:
20: 11 05 38 FE 01
40: 00

After Execution:
i. For largest ii. For Smallest

20: 11 05 38 FE 01 20: 11 05 38 FE 01

40: FE 40:01
Counters

13. Write an ALP for Decimal UP-Counter. (Ex: Count from 05 to 55)

org 0h
rpt: mov r6,#05h
nxt: lcall delay
mov a, r6
add a, #01
DA A
mov r6,a
cjne r6, #56h, nxt
sjmp rpt
delay: mov r2, #0ffh
rep2: mov r3, #0ffh
rep1: mov r4, #0ffh
rep: djnz r4,rep
djnz r3, rep1
djnz r2, rep2
ret
end

Output: mem loc I: 0x06 reg


05

.
55
14. Write an ALP for Decimal DOWN-Counter. (Ex: Count from 50 to 10)

org 0h
rpt: mov r6,#50h
nxt: lcall delay
mov a,r6
add a,#99h
DA A
mov r6,a
cjne r6,#09h,nxt
sjmp rpt
delay: mov r2,#0ffh
rep2: mov r3,#0ffh
rep1: mov r4,#0ffh
rep: djnz r4,rep
djnz r3,rep1
djnz r2,rep2
ret
end

Output: I: 0x06
50

.
10
15. Write an ALP for Hexadecimal UP-Counter. (Ex: Count from 11h to
AAh)

org 0h
rpt: mov r6,#11h
nxt: lcall delay
inc r6
cjne r6,#0ABh, nxt
sjmp rpt
delay: mov r2,#0ffh
rep2: mov r3,#0ffh
rep1: mov r4,#0ffh
rep: djnz r4,rep
djnz r3,rep1
djnz r2,rep2
ret
end

Output: I: 0x06
11

.
AA
16. Write an ALP for Hexadecimal DOWN-Counter. (Ex: Count from AAh
to 55h

org 0h
rpt: mov r6,#0AAh
nxt: lcall delay
dec r6
cjne r6,#54h, nxt
sjmp rpt
delay: mov r2,#0ffh
rep2: mov r3,#0ffh
rep1: mov r4,#0ffh
rep: djnz r4,rep
djnz r3,rep1
djnz r2, rep2
ret
end

Output: I: 0x06
AA

.
55

You might also like