0

I'm trying to create a program in Easy68K that is able to test if two numbers entered by the user are equal. I know roughly how to get the input from the user, and load it into a data register, and I think I need to use a while loop that will test whether the two numbers are equal.

I'm not asking for people to write the program for me, I just really need some advice.

This is the code I have so far:

*-----------------------------------------------------------
* Title      : Number Comparison
* Written by : Robert Dudley
* Date       : 23/04/2017
* Description: Compares two numbers and determines if they are equal
*-----------------------------------------------------------
    ORG    $1000
START:                                      ; first instruction of program

* Put program code here

     LEA        enterFirst,A1             ; load message into adreg A1
     MOVE.B     #14,D0
     TRAP       #15
     MOVE.B     #4,D0                      ; read number from keyboard into D1.L
     TRAP       #15

     LEA        enterSecond,A1
     MOVE.B     #14,D0
     TRAP       #15
     MOVE.B     #4,D0
     TRAP       #15

     SIMHALT                                ; halt simulator

* Put variables and constants here

enterFirst      DC.B    'Enter first number: ',0
enterSecond     DC.B    'Enter second number: ',0

                END    START                ; last line of source

NOTE: Also, how do I move the input from D1.L to another register?

Rob Dudley
  • 25
  • 8

2 Answers2

0

The keyboard input routine most probably leaves the entered number in some register, let's assume it's D1. Entering the second value will destroy the first one if not saved somewhere else. (I guess this is why you asked how to move a value from one register to the other)

Insert the following line after the second TRAP 15:

     MOVE.L d1,d7

Make sure none of the traps changes this register value - otherwise you will lose it.

After the second keyboard input, you will have the second number in d1, the first one (hopefully) still in d7. CoMPare the two registers, and use a conditional branch to whatever [non]equality output routine you might write

tofro
  • 5,640
  • 14
  • 31
  • Thanks! The problem I'm now facing is saving the second value (D1.L needs to be used again to display results), and actually displaying D7. Otherwise at least it's now storing the value of the first input. – Rob Dudley Apr 23 '17 at 18:26
  • Never mind! I've been working on it that long I went a bit brain dead, but I've got the basics now. Thank you so much for your help! – Rob Dudley Apr 23 '17 at 18:42
0

Here is code that can serve as a reference. It compares if a number is greater, less or equal to another number:

    START:                  ; first instruction of program

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

    MOVE.B #4, D0 
    TRAP #15

    CMP.L #5, D1 
    BEQ ESCINCO 

    CMP.L #5, D1 
    BGT MAYORQUE  

    CMP.L #5, D1 
    BLT MENORQUE 

MAYORQUE 
    LEA MAYOR, A1 
    MOVE.B #14, D0
    TRAP #15

    MOVE.B #9, D0
    TRAP #15

MAYOR DC.B 'EL VALOR EL MAYO QUE 5',0 
    rts 

MENORQUE 
    LEA MENOR, A1
    MOVE.B #14, D0 
    TRAP #15

    MOVE.B #9, D0 
    TRAP #15

MENOR DC.B 'EL VALOR ES MENOR QUE 5',0 
    rts 

ESCINCO 
    LEA IGUALACION, A1
    MOVE.B #14, D0 
    TRAP #15

    MOVE.B #9, D0 
    TRAP #15 

IGUALACION DC.B 'EL VALOR ES 5',0
    rts

SELECCION DC.B 'INGRESE DIGITOS ENTRE 0 Y 9: ',0
    END START
    END    START        ; last line of source
sth
  • 222,467
  • 53
  • 283
  • 367
Cris Valdez
  • 101
  • 1