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.

[PIC] Compare two 4 bit numbers using PIC16f676 in Assembly Language

Status
Not open for further replies.

coder123

Newbie level 4
Joined
Jun 11, 2015
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
42
I nedd help with the following problem statement, Thank you

Suppose there are two 4 bit numbers X and Y ( 0000,0001,....) .... if X>Y, Z=1 else Z=0

How do i code this is PIC16f676
 

What programming language are you using to code?

For C, you could use the ternary operator:

Code:
mask = 0x0F;

Z = (X & mask) > (Y & mask) ? 1 : 0;

A bitwise mask is used to ensure the first four bits of each value are cleared.

Example Code for PC:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
 
 
int main(void)
{
    unsigned char X = 5;
    unsigned char Y = 3;
    unsigned char Z;
    unsigned char mask = 0x0F;
 
    Z = (X & mask) > (Y & mask) ?  1 :  0;
 
    if(Z)
    {
        printf("X is greater than Y\n");
    }
    else
    {
        printf("Y is greater or equal to X\n");
    }
 
    return 0;
}




BigDog
 

I need the code in assembly language.
I also need the code where you initialise the input and output ports .

Thanks a lot
 

Hi,

I also need the code where you initialise the input and output ports .
you have to tell use where are the inputs and outputs.

Klaus
 

Just tell me the logic how will you compare two binary numbers in assembly language.
(without using and <, > or equal sign )
Binary comparison

If you can help with the assmebly language code that will be great
 

Subtract one from the other:

movlw number1
movwf SomeLocation
movlw number2
subwf Somelocation,f

Then check the STATUS register. The Z flag will be set if the values are equal and if it isn't set, the C flag tells you which number is larger.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top