8051 assembly program to check for palindrome number

;number is stored at location 70H
;palindrome status is stored at 60H
;if palindrome then 60H will hold 01 else 00
;P1.0 is cleared in case of palindrome else set to 1
;A LED can be connected to P1.0 to display palindrome status
setb P1.0
mov r0,#70H
mov r1,#72H
mov a,@r0
mov r2,a
mov r0,#60h ;palindrome status
mov @r0,#00
mov r3,#00
mov b,#100
div ab
jz next
mov @r1,a
inc r1
mov a,b
inc r3
jmp divby10
next:
mov a,r2
divby10:
mov b,#10
div ab
jz next1
mov r2,a
mov @r1,a
inc r1
mov a,b
inc r3
jmp divby1
next1:
mov a,r2
divby1:
mov @r1,a
inc r3
mov R1,#72H
mov a,r3
subb a,#01
jz only1
mov a,r3
subb a,#02
jz only2
mov a,r3
subb a,#03
jz only3
mov @r0,#00
here:sjmp here
only1:
mov @r0,#01
clr P1.0
jmp here
only2:
mov a,@r1
inc r1
subb a,@r1
jnz here
clr P1.0
mov @R0,#01
jmp here
only3:
mov a,@r1
inc r1
inc r1
subb a,@r1
jnz here
clr P1.0
mov @r0,#01
jmp here
end

 

Walkthrough of KEIL uVision IDE

Basic KEIL Tutorial

Starting a new Assembler Project
1. Select New Project from the Project Menu.
2. Name the project ‘led’
3. Click on the Save Button.
4. The device window will be displayed.
5. Select the part you will be using to test with. For now we will use the ATMEL Microcontroller AT89C52
6. Double Click on ATMEL.
7. Scroll down and select AT89C52
8. Click OK
 
Creating Source File
1. Click File Menu and select New
2. A new window will open up in Keil IDE
3. Copy the example given below into the new window.
4. Click on File Menu and select Save As
5. Name the file as “led.asm”
6. Click the Save button
 
Adding File to the Project
1. Expand Target 1 in the Project Workspace
2. Double Click on Source Group File
3. A window will open
4. Give file name as “led.asm”
5. Click on Add button
 
Testing Program in Debugger
1. Click on Project Menu and select Rebuild All Target Files
2. In the Build Window it should report ' 0 Errors, 0 Warnings'
3. Click on Debug Menu and select Start/Stop Debug Seesion
4. Click on Debug menu and select Run
5. The Keil Debugger now should be running
6. Click on Peripherals menu and select I/O Ports, select Port 2
7. A new window pops up. This represents the port and pins.
8. To exit out click on Debug menu, select Stop Running, again click on Debug menu select Start/Stop
Debug Session
 
Accessing Internal RAM
1. Click on Debug Menu and select Start/Stop Debug Seesion
2. Click on View Menu and select Memory Window
3. A Memory Window with four memory tabs (Memory#1,#2,#3,#4) will open in the workarea
4. In the address bar type i:60h to access internal memory addrees 60h.
5. Memory address will change in the window to I:0x60 : 00 00 ……
6. Right Click on first memory address 00 and select Unsigned -> Char
7. Again, right click on the same and select Modify memory at I:0x60
8. Enter an 8 bit data
9. Press OK
 
Note: I represents internal memory, similarly X represents external memory and C represents code memory.
 
 

Sorting of number in ascending and descending order

;Sorting of array in ascending order 
;Array size is 04
;Array starting address is 70h
ORG 00h
ARR EQU 70h
L0:
 MOV R1,#ARR
 MOV R0,#ARR
 MOV R2,#04h
 MOV R3,#00h
 DEC R2
 L1:
  MOV A,@R0
  MOV B,A
  INC R1
  SUBB A,@R1
  JC L2
  MOV A,B
  XCH A,@R1
  MOV @R0,A
  MOV R3,#01h
  L2:
  INC R0
 DJNZ R2,L1
CJNE R3,#00,L0 
SJMP $
END

;Sorting of array in descending order 
;Array size is 04
;Array starting address is 70h
ORG 00h
ARR EQU 70h
L0:
 MOV R1,#ARR
 MOV R0,#ARR
 MOV R2,#04h
 MOV R3,#00h
 DEC R2
 L1:
  MOV A,@R0
  MOV B,A
  INC R1
  SUBB A,@R1
  JNC L2
  MOV A,B
  XCH A,@R1
  MOV @R0,A
  MOV R3,#01h
  L2:
  INC R0
 DJNZ R2,L1
CJNE R3,#00,L0 
SJMP $
END

Find the positive and negative number in an array

;Number of positive and negative numbers in an 8 bit array 
;Array size is 04
;Array starting address is 70h
;Positive count is stored at 50h
;Negative count is stored at 60h
ORG 00h
NEG EQU 50h
POS EQU 60h
ARR EQU 70h
MOV R5,#00h
MOV R6,#00h
MOV R1,#ARR
MOV R2,#04h
L1:
 CLR C
 MOV A,@R1
 RLC A
 JNC L2
 INC R5
 JMP L3
 L2:
  INC R6
 L3:
  INC R1
DJNZ R2,L1
MOV NEG,R5
MOV POS,R6 
SJMP $
END

Count the number of even and odd numbers in an array

;Number of odd and even numbers in an 8 bit array 
;Array size is 04
;Array starting address is 70h
;Odd count is stored at 50h
;Even count is stored at 60h
ORG 00h
ODD EQU 50h
EVEN EQU 60h
ARR EQU 70h
MOV R5,#00h
MOV R6,#00h
MOV R1,#ARR
MOV R2,#04h
L1:
 CLR C
 MOV A,@R1
 RRC A
 JNC L2
 INC R5
 JMP L3
 L2:
  INC R6
 L3:
  INC R1
DJNZ R2,L1
MOV ODD,R5
MOV EVEN,R6 
SJMP $
END