C and Assembly Mixed-Mode Hex comparison program

Thread Solved

Join Date: Sep 2009
Posts: 3
Reputation: HypnotiqBIG is an unknown quantity at this point 
Solved Threads: 0
HypnotiqBIG HypnotiqBIG is offline Offline
Newbie Poster

C and Assembly Mixed-Mode Hex comparison program

 
0
  #1
21 Days Ago
Hi, I have an assignment where i have to write a C and assembly mixed-mode program.
  1. The c program takes in two characters which stand for two hex characters.
  2. The assembly procedure then passes each character in turn to a C function which determines if the character is a valid ASCII HEX digit (namely 0-F).
  3. If both characters are valid the assembly language procedure then compares the two HEX digits and returns the larger to the main program.
  4. The main C program then prints out the larger digit.

I am unsure how to do no. 2, namely, how to determine if it's a valid ASCII HEX digit or just garbage. Suggestions?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 354
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 44
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Whiz
 
0
  #2
21 Days Ago
Could we see what you have so far?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 3
Reputation: HypnotiqBIG is an unknown quantity at this point 
Solved Threads: 0
HypnotiqBIG HypnotiqBIG is offline Offline
Newbie Poster
 
0
  #3
20 Days Ago
So far I have my C file taking in 2 characters:
  1. char char1, char2;
  2. printf ("Enter a character: ");
  3. scanf ("%c", &char1);
  4.  
  5. while (getchar () != '\n')//so that the program doesn't take in the carriage return as input
  6. continue;
  7.  
  8. printf ("Enter another character: ");
  9. scanf ("%c", &char2);
  10.  
  11. while (getchar () != '\n')//so that the program doesn't take in the carriage return as input
  12. continue;

And I'm just not sure how to verify if their HEX or just normal characters (so either 0-9 or A-F). I was thinking I could just do a bunch of if statements comparing each of them (or make a HEX array, and for loop through it comparing along the way), but is there a better way to do this?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 354
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 44
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Whiz
 
0
  #4
20 Days Ago
Originally Posted by HypnotiqBIG View Post
So far I have my C file taking in 2 characters:
  1. char char1, char2;
  2. printf ("Enter a character: ");
  3. scanf ("%c", &char1);
  4.  
  5. while (getchar () != '\n')//so that the program doesn't take in the carriage return as input
  6. continue;
  7.  
  8. printf ("Enter another character: ");
  9. scanf ("%c", &char2);
  10.  
  11. while (getchar () != '\n')//so that the program doesn't take in the carriage return as input
  12. continue;

And I'm just not sure how to verify if their HEX or just normal characters (so either 0-9 or A-F). I was thinking I could just do a bunch of if statements comparing each of them (or make a HEX array, and for loop through it comparing along the way), but is there a better way to do this?
C has a function called isxdigit which checks if the character is 0 -9 or a - f maybe you could use that...
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 3
Reputation: HypnotiqBIG is an unknown quantity at this point 
Solved Threads: 0
HypnotiqBIG HypnotiqBIG is offline Offline
Newbie Poster
 
0
  #5
20 Days Ago
That worked perfectly thank you, I'll mark it as solved for now if more problems come up I'll change that
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC