954,170 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C and Assembly Mixed-Mode Hex comparison program

Hi, I have an assignment where i have to write a C and assembly mixed-mode program. The c program takes in two characters which stand for two hex characters.
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).
If both characters are valid the assembly language procedure then compares the two HEX digits and returns the larger to the main program.
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?

HypnotiqBIG
Newbie Poster
3 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

Could we see what you have so far?

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 

So far I have my C file taking in 2 characters:

char char1, char2;
    printf ("Enter a character: ");
    scanf ("%c", &char1);
    
    while (getchar () != '\n')//so that the program doesn't take in the carriage return as input
        continue;
    
    printf ("Enter another character: ");
    scanf ("%c", &char2);
    
    while (getchar () != '\n')//so that the program doesn't take in the carriage return as input
        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?

HypnotiqBIG
Newbie Poster
3 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

So far I have my C file taking in 2 characters:

char char1, char2;
    printf ("Enter a character: ");
    scanf ("%c", &char1);
    
    while (getchar () != '\n')//so that the program doesn't take in the carriage return as input
        continue;
    
    printf ("Enter another character: ");
    scanf ("%c", &char2);
    
    while (getchar () != '\n')//so that the program doesn't take in the carriage return as input
        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...

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 

That worked perfectly thank you, I'll mark it as solved for now if more problems come up I'll change that :)

HypnotiqBIG
Newbie Poster
3 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You