Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Assembler Mplab. AND, OR, XOR

Status
Not open for further replies.

metals

Junior Member level 2
Joined
Jan 25, 2011
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,441
Hi!

I am supposed to write a program in Mplab with assembler that calculates the logical and, or and xor bitwise between two variables.

I know that I can and should use ANDLW/ANDWF and XORLW/XORWF.

But else I have no idea. Can anyone help me please? :(
 

Put one variable in a memory location and the other in the W register.
Each of the instructions can perform the logical operation and leave the result in either W or the memory location depending on the 'destination' specified in the instruction.

For example:
suppose the two variables are stored in Var1 and Var2 -
movf Var1,W ;this puts Var1 in the W register
andwf Var2,W ;this does a logic AND and leaves the result in W

you could change the second line to
andwf Var2,F ;this does the logic AND and puts the result back where Var2 is stored

the same principle applies to the other logic functions, XORLW and IORLW.

Brian.
 

Okay this is what I have managed to write;


status equ 0x03
VAR_A equ 0x20
VAR_B equ 0x21
RES_and equ 0x22 ;Where I want the result to be stored
RES_or equ 0x23
RES_xor equ 0x24

;***************************************************************
org 0x00
clrf status
movlw 0x00
movwf 0x0A
goto main
;****************************************************************
main call init
call subrut_and
call subrut_or
call subrut_xor

;****************************************************************
init clrw
movlw 0x55
movwf VAR_A
movlw 0x56
movwf VAR_B


;********subrutiner*************************************************
sub_and movlw 0x55
movf VAR_A,W
andwf VAR_B,F


and I have no idea if its correkt or not :(
 

NOT correct !!

1. don't use "status equ 0x03", use the include file provided with MPLAB instead, it will associate ALL the registers and bits with their names so you don't have to do it yourself.
2. I've no idea what you intended to do by loading value 0 into address 0x0A, on 16F devices it is the PCLATH register, it does other things on PIC18F devices.
3. When you use the "call" instruction, it goes to the routine you name but to get back you must use a return instruction at the end of it. At the moment, at the end of the routine you call it just moves on to whatever is at the next address.

The logic operations are correct but you are not storing the result in the 'RES_' register as you want to.

Brian.
 
  • Like
Reactions: metals

    metals

    Points: 2
    Helpful Answer Positive Rating
I finally did it! And thank you for tips 1. I have not heard about it before but will now definitely check it out.

thank you =)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top