Jun 18, 2015 #1 C 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
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
Jun 18, 2015 #2 bigdogguru Administrator Joined Mar 12, 2010 Messages 9,821 Helped 2,350 Reputation 4,694 Reaction score 2,272 Trophy points 1,413 Location Southwest, USA Activity points 62,389 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
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
Jun 18, 2015 #3 C coder123 Newbie level 4 Joined Jun 11, 2015 Messages 7 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 42 I need the code in assembly language. I also need the code where you initialise the input and output ports . Thanks a lot
I need the code in assembly language. I also need the code where you initialise the input and output ports . Thanks a lot
Jun 18, 2015 #4 KlausST Advanced Member level 7 Joined Apr 17, 2014 Messages 25,947 Helped 4,910 Reputation 9,843 Reaction score 5,726 Trophy points 1,393 Activity points 174,110 Hi, I also need the code where you initialise the input and output ports . Click to expand... you have to tell use where are the inputs and outputs. Klaus
Hi, I also need the code where you initialise the input and output ports . Click to expand... you have to tell use where are the inputs and outputs. Klaus
Jun 18, 2015 #5 C coder123 Newbie level 4 Joined Jun 11, 2015 Messages 7 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 42 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
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
Jun 18, 2015 #6 betwixt Super Moderator Staff member Joined Jul 4, 2009 Messages 16,458 Helped 5,156 Reputation 10,341 Reaction score 5,194 Trophy points 1,393 Location Aberdyfi, West Wales, UK Activity points 139,286 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.
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.