EASy68K  
It is currently Fri Jun 05, 2020 7:14 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Dec 08, 2013 6:44 am 
Offline

Joined: Sat Nov 16, 2013 12:06 pm
Posts: 1
I facing problem for the comparing between the higher ODD integer . Is that any other way to do it ?


Code:
Write a program that will perform the searhing for the highest ODD integer.

Ask for an input string (up to 5 characters) from the user. Display each character to the screen as the user types it in. If the user attempts to enter more than 5 characters, given an error message and terminate the program.

   Example:
   Please enter a string of characters to search for the highest ODD integer:

      25376
   
   7 is the highest ODD integer.



this is my code:


Code:
START   ORG   $1000

CR       EQU      $D
LF       EQU      $A
   

    * PROMPT FOR INPUT
   LEA MSG1,A1
   MOVE.B   #14,D0
   TRAP    #15

   MOVE.B   #4,D0
   TRAP   #15
   MOVE.W   D1,A5


   LEA MSG1,A1
   MOVE.B   #14,D0
   TRAP    #15

   MOVE.B   #4,D0
   TRAP   #15
   MOVE.W   D1,A6


   LEA MSG1,A1
   MOVE.B   #14,D0
   TRAP    #15

   MOVE.B   #4,D0
   TRAP   #15
   MOVE.W   D1,D4


   LEA MSG1,A1
   MOVE.B   #14,D0
   TRAP    #15

   MOVE.B   #4,D0
   TRAP   #15
   MOVE.W   D1,D3
   

   LEA MSG1,A1
   MOVE.B   #14,D0
   TRAP    #15

   MOVE.B   #4,D0
   TRAP   #15
   MOVE.W   D1,D2


   LEA MSG1,A1
   MOVE.B   #14,D0
   TRAP    #15

   MOVE.B   #4,D0
   TRAP #15

   
   
CR       EQU      $D
LF       EQU      $A

MSG1   DC.B   'ENTER NUMBER: ',CR,LF,0



    SIMHALT

   END   START


Top
 Profile  
 
PostPosted: Wed Dec 25, 2013 12:08 pm 
Offline

Joined: Tue Nov 15, 2005 7:58 am
Posts: 129
Location: Oregon, USA
You've defined CR and LF twice.

The instructions appear to be saying to treat each digit (character) entered as a separate number.

Your program requests exactly 6 (not "up to 5") numbers (not characters), then stores them in arbitrary registers. It doesn't do anything else with them.

You need to write a loop that:
Code:
  inputs a single character (Task 5) and echoes it (Task 6)
  increments a count of characters read
  if it's an end-of-line (carriage-return, CR) character then
    exit the loop
  otherwise
    tests if it's odd.  If it is odd then
      tests if it's greater than the current largest odd number found so far, if so then
        remember it as the (new) largest so far
  If less than 5 characters have been input, goes back to the start of the loop for another character

When the loop ends, display the largest odd number (digit) found.

If you do it this way, there's no need to store all the characters.

Instead of inputting individual characters, you could input-with-echo a string of characters all at once, similar to what you're doing now, then test it one byte at a time in a loop -- but with e.g. Task 2, there's no way to prevent entering more than 5 characters. You could print the error message after the string has been read if it's too long, but that's not how I read the instructions ("attempts to").

You could convert the incoming ASCII characters to binary numbers (by subtracting '0' from each), but it's not necessary because an odd ASCII digit will also be an odd binary number.

I've deliberately omitted the test for and printing of the error message. You get to figure that out. As a hint, it will probably involve changing the end-of-loop test. If I were you, I'd get it working without the error test first, then add it later. You might even want to start by writing and testing code just to read and echo "up to 5" characters.

I notice that the behaviour of the program isn't specified in the case that either zero digits (just a CR) or any non-digit characters are entered. You're on your own for those.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group