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 “[Link]”
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.