8051 Assembly Code Formatting Demo


FormatCode Code Formatter is based on serveral powerful syntax parser engines so you can exactly control the appearance of your source code. Here is the code formatting demo of FormatCode Assembly 8051 / Asm51 Code Formatter to prove the ability of code formatting functions of FormatCode:

   ;--- Before Code Formatting ---

   RS EQU P3.0
   RW EQU P3.1
   E EQU P3.5
   mov p3,#0ffh
   MOV P1,#01H ; clear screen
   ACALL ENABLE
   MOV P1,#38H ; 8 bits
   ACALL ENABLE
   MOV P1,#0FH ; open
   ACALL ENABLE
   MOV P1,#06H ; move cursor
   ACALL ENABLE
   MOV P1,#80H ; show position
   ACALL ENABLE
   l3: mov p1,#01h
   acall enable
   mov dptr,#table1 ; the 1st word
   call write1
   call enable
   mov p1,#01h
   ljmp l1
   l4: mov p1,#01h
   acall enable
   mov dptr,#table2 ; the 2nd word
   call write1
   call enable
   mov p1,#01h
   ljmp l1
   l5: mov p1,#01h
   acall enable
   mov dptr,#table3 ; the 3rd word
   call write1
   acall enable
   mov p1,#01h
   ljmp l1
   l6:mov p1,#01h
   acall enable
   mov dptr,#table4 ; the 4th word
   call write1
   acall enable
   mov p1,#01h
   ljmp l1
   l1: jnb p3.3,l3 ; keyboard
   jnb p3.4,l4
   jnb p3.5,l5
   JNB P3.2,L6
   jmp l1
   ENABLE: ; send
   CLR RS
   CLR RW
   CLR E
   ACALL DELAY
   SETB E
   RET
   write1: ; send string
   mov r1,#00h
   a1:mov a,r1
   movc a,@a+dptr
   call write2
   inc r1
   cjne a,#00h,a1 ; 00H as string end
   ret
   write2: ; send single character
   mov p1,a
   setb rs
   clr rw
   clr e
   call delay
   setb e
   ret
   delay: ; delay sub function
   mov r7,#255
   d1:mov r6,#255
   d2:djnz r6,d2
   djnz r7,d1
   ret
   table1: db 20h,57h,57h,57h,2Eh,35h,31h,43h,35h,20h,20h,00h
   table2: db 53h,58H,4AH,31H,39H,37H,34H,40H,31H,20H,20h,00H
   table3: db 54h,45h,4Ch,30h,37h,35h,35h,20H,32H,35H,20H,00H
   Table4: db 49H,20H,4CH,4FH,56H,45H,20H,38H,39H,20H,20H,00H

   end


   ;--- After Code Formatting ---

               RS    equ P3.0
               RW    equ P3.1
               E     equ P3.5
               mov   p3, #0ffh
               mov   P1, #01H      ; clear screen
               acall ENABLE
               mov   P1, #38H      ; 8 bits
               acall ENABLE
               mov   P1, #0FH      ; open
               acall ENABLE
               mov   P1, #06H      ; move cursor
               acall ENABLE
               mov   P1, #80H      ; show position
               acall ENABLE
   l3:         mov   p1, #01h
               acall enable
               mov   DPTR, #table1 ; the 1st word
               call  write1
               call  enable
               mov   p1, #01h
               ljmp  l1
   l4:         mov   p1, #01h
               acall enable
               mov   DPTR, #table2 ; the 2nd word
               call  write1
               call  enable
               mov   p1, #01h
               ljmp  l1
   l5:         mov   p1, #01h
               acall enable
               mov   DPTR, #table3 ; the 3rd word
               call  write1
               acall enable
               mov   p1, #01h
               ljmp  l1
   l6:         mov   p1, #01h
               acall enable
               mov   DPTR, #table4 ; the 4th word
               call  write1
               acall enable
               mov   p1, #01h
               ljmp  l1
   l1:         jnb   p3.3, l3      ; keyboard
               jnb   p3.4, l4
               jnb   p3.5, l5
               jnb   P3.2, L6
               jmp   l1
   ENABLE:     ; send
               clr   RS
               clr   RW
               clr   E
               acall DELAY
               setb  E
               ret
   write1:     ; send string
               mov   R1, #00h
   a1:         mov   A, R1
               movc  A, @A+DPTR
               call  write2
               inc   R1
               cjne  A, #00h, a1   ; 00H as string end
               ret
   write2:     ; send single character
               mov   p1, A
               setb  rs
               clr   rw
               clr   e
               call  delay
               setb  e
               ret
   delay:     ; delay sub function
               mov   R7, #255
   d1:         mov   R6, #255
   d2:         djnz  R6, d2
               djnz  R7, d1
               ret

   table1:     db    20h, 57h, 57h, 57h, 2Eh, 35h, 31h, 43h, 35h, 20h, 20h, 00h
   table2:     db    53h, 58H, 4AH, 31H, 39H, 37H, 34H, 40H, 31H, 20H, 20h, 00H
   table3:     db    54h, 45h, 4Ch, 30h, 37h, 35h, 35h, 20H, 32H, 35H, 20H, 00H
   Table4:     db    49H, 20H, 4CH, 4FH, 56H, 45H, 20H, 38H, 39H, 20H, 20H, 00H

   end


Click here to preview the 8051 Assembly Code Formatting Demo 2.

With FormatCode 8051 Assembly Code Formatters, you can format and transform any foreign Asm51 source code to meet your preferred coding style or any common code convention in several seconds!