SECTION VI-2: Structure of Assembly Language

An assembly language program consists of, among other things, a series of lines of Assembly language instructions. An assembly language instruction consists of a mnemonic, optionally followed by one or two operands. The operands are the data items being manipulated, and the mnemonics are the commands to the CPU, telling it what to do with those items.

An assembly language program is a series of statements, or lines, which are either assembly language instructions such as ADDLW and MOVWF, or statements called directives. While instructions tell the CPU what to do. Directives, also called pseudo-instructions given directions to the assembler. The directive ORG tells the assembler to place the opcode at memory location 0 while END indicates the end of the source code to the assembler. One directive is for the start of the program and the other for the end of the program.

An assembly language instruction consists of four fields:

[ label ] mnemonic [ operands ] [ ;comment ]

 

 

Brackets indicate that a field is optional and not all lines have them. Brackets should not be typed in. Regarding the above format, the following points should be noted:

  •  The label field allows the program to refer to a line of code by name. The label field cannot exceed a certain number of characters.

 

  • The Assembly Language mnemonic (instruction) and operand fields together perform the real work of the program and accomplish the tasks for which the program was written. An Assembly Language such as: 

 

MOVLW 55H
ADDLW 67H

 

 

 

ADDLW and MOVLW are the mnemonics that produce opcodes; the "55H" and "67H" are the operands. Instead of a mnemonic and an operand, these two fields could contain assembler pseudo-instructions, or directives. Directives do not generate any machine code (opcode) and are used only by the assembler, as opposed to instructions that are translated into machine code (opcode) for the CPU to execute. The commands ORG (origin) and END are examples of directives.

  • The comment field begins with a semicolon comment indicator " ; " . Comments may be at the end of a line or on a line by themselves. The assembler ignores comments, but they are indispensable to programmers. Comments are optional.. They be used to describe the program in a way that makes it easier for someone else to read and understand.

 

  • The label "HERE" in the label field in below program. In the GOTO the PIC is told to stay in this loop indefinitely. If your system has a monitor program you do not need this line and it should be deleted from your program.

 

;PIC Assembly Language Program To Add Some Data.
;Store SUM in fileReg location 10H.
SUM EQU 10H ;RAM location 10H for SUM
ORG 0H ;start at address 0
MOVLW 25H ;WREG = 25H
ADDLW 0x34 ;add 34H to WREG
ADDLW 11H ;add 11H to WREG
ADDLW D'18' ;W = W + 12H = 7CH
ADDLW 1CH W = W + 1CH = 98H
ADDLW B'00000110' W = W + 6 = 9EH
MOVWF SUM ;Save the SUM in location 10H
HERE GOTO HERE Say here forever
END ;end of asm source file

 

 

 

 

 

 

 

 

 

 

 

 

More From Iamtechnical.com

Advertisement:

SiteLock