//------------------------------------------------------------------- // iseven.cpp // // This is a high-level language 'prototype' (written in C++) // for a program you are asked to write in assembly-language. // In case a number is entered as a command-line argument, it // determines whether or not that number was an even integer. // // compile-and-link using: $ g++ iseven.cpp -o iseven // and then execute using: $ ./iseven // // NOTE: The purpose of a 'prototype' is to help you identify // all the program-variables and algorithm-steps your program // will need. Of course, your assembly language program will // not necessarily find its command-line argument in the same // way that C++ does, nor will it be allowed to call standard // functions in the C/C++ runtime-libraries, but it will need // to use its own ways of accomplishing those same effects. // // programmer: ALLAN CRUSE // written on: 25 FEB 2007 //------------------------------------------------------------------- #include // for exit(), atoi() #include // for strlen() #include // for write() int main( int argc, char **argv ) { // exit in case the command-line argument is missing if ( argc == 1 ) exit(1); // otherwise convert the argument-string to an integer int arg = atoi( argv[1] ); // then report on whether the number is even or not int remainder = arg % 2; int arglength = strlen( argv[1] ); write( STDOUT_FILENO, argv[1], arglength ); if ( remainder == 0 ) { char message0[] = " is an even number \n"; int msg0len = strlen( message0 ); write( STDOUT_FILENO, message0, msg0len ); } else { char message1[] = " is not an even number \n"; int msg1len = strlen( message1 ); write( STDOUT_FILENO, message1, msg1len ); } }