Saturday 26 January 2013

My First Program In Assembly Language

How to write first program in Assembly Language?

First of all you should know that method of creating file. You can use any IDE for writing your program. you can use 8051 ID or you can use KEIL software. You only have to save file and assemble it. Your ID will automatically link it and will give you HEX file. You can use that HEX file in to your microcontroller.


Your Program should have following four parts.

  • Starting Point ORG 00H, this is directive and is only for compiler.
  • Instructions like MOVE, ADD etc.
  • You can use comments and for this you have to use ";" symbol fot making any kind of wods in coments, as in example below.
  • You canm use lebels to organise your progra, as in example below i use " HERE: " as lebel. 
  • There hould be a word "END" in the end of every program.


ORG 00H         ;start(origin) at location0
      MOV R5, #25H ;load 25H into R5
      MOV R7, #34H ;load 34H into R7
      MOV A, #0         ;load 0 into A
      ADD A, R5         ;add contents of R5 to A
                         ;now A = A + R5
     ADD A, R7         ;add contents of R7 to A
                         ;now A = A + R7
     ADD A, #12H         ;add to A value 12H
                         ;now A = A + 12H
HERE:
     SJMP HERE                 ;stay in this loop

END


after writing this you have to save your program by the extention of ".asm" and then assemble it. As a result it will generate ".hex" file which you can burn in your microcontroller.

No comments:

Post a Comment