Thursday, 22 December 2011

Basic Microcontroller Programs

1.  8 bit addition:
clr c
mov a,#10
add a,#09
end

2.  8 bit subtraction:
clr c
mov a,#10
subb a,#09
end


3.  8 bit multiplication:
clr c
mov a,#03h
mov b,#01h
mul ab
mov r1,a
mov r0,b
end

4.  8 bit division:
clr c
mov a,#03h
mov b,#04h
div ab
mov r1,a
mov r0,b
end

5.  16 bit addition:
clr c
mov a,#05h
mov r0,#06h
mov r1,#08h
mov r2,#07h
add a,r1
mov r6,a
mov a,r0
addc a,r2
mov r5,a
end

6. 16 bit subtraction:
clr c
mov a,#05h
mov r0,#06h
mov r1,#08h
mov r2,#07h
subb a,r1
mov r6,a
mov a,r0
subb a,r2
mov r5,a
end


7.  16 bit to 8 bit multiplication:
[             r0b
            *     a
             r6r7         ]
(clr c
mov r0,#43h
mov b,#21h
mov a,#0ah
mul ab
mov r7,a
mov r6,b
mov a,#0ah
mov b,r0
mul ab
add a,r6
jnc next
inc r6
next:mov r6,a
mov r5,b
end)

8.  16 bit to 16 bit multiplication:
[             r0r1
            *r2r3
     r4r5r6r7         ]
clr c
mov r0,#01fh
mov r1,#02fh
mov r2,#08fh
mov r3,#09fh
mov b,r1
mov a,r3
mul ab
mov r7,a
mov r6,b
mov b,r3
mov a,r0
mul ab
add a,r6
jnc next
inc b
next:mov r6,a
mov r5,b
mov b,r1
mov a,r2
mul ab
add a,r6
jnc next1
inc r5
next1:mov r6,a
mov a,b
add a,r5
jnc next2
inc r4
next2:mov r5,a
mov b,r0
mov a,r2
mul ab
add a,r5
jnc next3
inc r4
next3:mov r5,a
mov a,r4
add a,b
mov r4,a
end

No comments:

Post a Comment