RES Example

MPASM Assembler

RES Example

Directives highlighted in this example are:

  • res

Program Functional Description

This example shows the advantage of res directive in developing relocatable code. The program calculates the perimeter of a rectangle. Length and width of the rectangle will be stored in buffers addressed by length and width. The calculated perimeter will be stored in the double-precision buffer addressed by perimeter.

Commented Code Listing

list p=18c452 ;Select device.

#include <p18c452.inc> ;Include standard header file

;for the selected device.

UDATA ;This directive allows the

;following data to be placed only

;in the data area.

perimeter res 2 ;Two locations of memory are

;reserved for the label

;'perimeter'. Addresses of the

;memory locations will be

;allocated by MPLINK.

length res 1 ;One location of memory is

;reserved for the label 'length'.

;Address of the memory location

;will be allocated by MPLINK.

width res 1 ;One location of memory is

;reserved for the label 'width'.

;Address of the memory location

;will be allocated by MPLINK.

Start CODE 0000 ;Following code will be placed in

;address 0.

goto PER_CAL ;Jump to label PER_CAL

CODE ;CODE directive here dictates that

;the following lines of code will

;be placed in program memory, but

;the starting address will be

;decided by MPLINK.

PER_CAL

clrf perimeter ;Clear the buffers addressed by

clrf perimeter+1 ;'perimeter'.

movf length,w ;Move the data present in the

;register addressed by 'length'

;to 'w'.

addwf width,w ;Add data in 'w' with data in the

;register addressed by 'width'

movwf perimeter ;Move 'w' to the register

;addressed by 'perimeter'.

incfsz perimeter+1 ;Increment 'perimeter+1' if carry

;is generated.

bcf STATUS,C ;Clear carry bit in STATUS

;register.

rlf perimeter+1

rlf perimeter

incfsz perimeter+1

goto $

end


Microchip Technology Inc.
Microchip's Web Site
Voice: (480) 792-7200
Fax: (480) 899-9210
Microchip's E-mail Address
PreviousNext