0% found this document useful (0 votes)
39 views

Lab1: First Assembly Code Omar Kassar 201503246 Objective:: Equipment

This document describes a lab experiment to write a first assembly code program using a PIC16F84A microcontroller. The objective is to perform arithmetic computations and store the result at two addresses. The code adds the values (1+3), (4+6), and (7+1) and stores the decimal result of 22 at addresses 21H and 22H. Temporary variables like TEMP1 are used to store intermediate values since the working register W can only hold one value at a time. The code demonstrates instructions like MOVWF to move values to registers and memory locations and perform the arithmetic operations.

Uploaded by

Omar F'Kassar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Lab1: First Assembly Code Omar Kassar 201503246 Objective:: Equipment

This document describes a lab experiment to write a first assembly code program using a PIC16F84A microcontroller. The objective is to perform arithmetic computations and store the result at two addresses. The code adds the values (1+3), (4+6), and (7+1) and stores the decimal result of 22 at addresses 21H and 22H. Temporary variables like TEMP1 are used to store intermediate values since the working register W can only hold one value at a time. The code demonstrates instructions like MOVWF to move values to registers and memory locations and perform the arithmetic operations.

Uploaded by

Omar F'Kassar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab1: First assembly code

Omar Kassar 201503246


Objective: in this experiment, we will write our first assembly code in order to :

Equipment:
• IC: PIC16F84A
• Switches
• LED
• Test board
• PIC programmer
• Resistors (1KOhm and 270ohm)

Ex:
Write a code that does the following computation and send 2 copies of the
answer to the following addresses: 21H and 22H
(1+3)+(4+6)+(7+1)=22(base 10)=16(base 16)=0001 0110(base 2)

# INCLUDE “P16F84A.INC”
RESULT1 EQU 0X21
RESULT2 EQU 0X21
TEMP1 EQU 0X21
TEMP2 EQU 0X21
TEMP3 EQU 0X21

{ CONFI ORG 0X00


BSF STATUS,RP0
MOVLW H'3F'
MOVWF TRISA TRISA=1F(setting input)
MOVLW H'00'
MOVWF TRISB TRISB=00H(setting output)
BCF STATUS,RP0 back to bank 0
INIT CLRF PORTB clearing port b
CLRF RESULT1
CLRF RESULT2

MAIN2 MOVLW H'01' beginning of the code


ADDLW H'03'
MOVWF TEMP1
MOVLW H'04'
ADDLW H'06'
MOVWF TEMP2
MOVLW H'07'
ADDLW H'01'
MOVWF TEMP3
MOVF TEMP1,W
ADDWF TEMP2,W
ADDWF TEMP3,W
MOVWF RESULT1
MOVWF RESULT2
MOVWF PORTB }
Note: why do we need variables like TEMP1,TEMP2..?
Answer: W (the working register) is a unique register, only 1 copy of this register
exist. That’s why (1+3) is stored in a variable TEMP1 which has its own address to
be used later in the calculation.
Explanation of certain instruction:
• BSF STATUS,RP0 : bit set file, the program will go to bank1. We need bank 1
because there is TRISA (input) and TRISB (output).Also this instruction is
needed because the memory is by default in bank0.
• STATUS: register which contains arithmetic status of ALU
• # INCLUDE “P16F84A”: defining the library for our micro
• RESULT1 EQU 0X21: creation of a new variable named “RESULT” which has
an address:H’21’ ; EQU means equalize
Note: in general, the CONFI will be the same in our next exercices, if something
change I will repost the new CONFI
Conclusion: after finishing this ex, we have accomplished our purpose in
writing our first assembly code and get used to data transfer and arithmetic
instructions.

You might also like