How to write a program to find the lowest ODD integer in 68000 assembly?

378 views Asked by At

How to write a program to find the lowest ODD integer in a string of digits entered by the user? For example: I type 27385, so 3 is the lowest odd integer.

1

There are 1 answers

0
Devolus On BEST ANSWER

You can take adavtange of the fact that in binary a number is odd, when the lowest bit is set, otherwise it is even. Since the ASCII value of a digit is almost the direct representation of the number itself, you can use it as is, or subtract 0x30 to get the binary number from the digit char you are looking at.

Pseudocode (loop through the string):

  1. init result with a high/impossible value (0xff)
  2. read char
  3. if char == 0 -> jmp end
  4. sub 0x30 ; this is not really needed, depends on what output is expected.
  5. If lowest bit is zero -> jmp 2 ; Number is even
  6. if number is lower then current lowest number -> store it as new result
  7. jmp 2
  8. end