Smallest of 2 values in 68000

Assignment 15 

Homework Assignment 

Write an MC68000 program that will print out the smaller of two numbers inputted from
the terminal. The program should prompt the user to input the numbers and then output
the result after a statement indicating the result.
The initial prompts can be “Please input the first number:” and “Please input the second
number:”. The output statement can be “The smaller of the two numbers is:”.
Submit your program file (with extension .X68) along with representative results with the
normal naming convention as paper copies in the class on or before the due date.

Solution

ORG    $1000

FIRST:  DC.B    ‘Please input the first number: ‘

DC.B    0

DS.W    0

SECOND: DC.B    ‘Please input the second number: ‘

DC.B    0

DS.W    0

OUTPUT: DC.B    ‘The smaller of the two numbers is: ‘

DC.B    0

DS.W    0

ORG     $1500

START:                      ; first instruction of program

MOVEA.L #FIRST,A1   ; prompt the user for the first number

MOVE.L  #13,D0

TRAP    #15

MOVE.L  #4,D0       ; read a number from the user into D1.L

TRAP    #15

MOVE.L  D1,D2       ; save read number in D2 to use it later

MOVEA.L #SECOND,A1  ; prompt the user for the second number

MOVE.L  #13,D0

TRAP    #15

MOVE.L  #4,D0       ; read another number from the user into D1.L

TRAP    #15

MOVEA.L #OUTPUT,A1  ; print the output statement

MOVE.L  #13,D0

TRAP    #15

CMP.L   D2,D1       ; compare the first number with the last one read

BLT     D1SMALL     ; if D1 is smaller, go to print D1

D2SMALL:                    ; else, D2 is smaller, print it

MOVE.L  D2,D1       ; move D2 to D1 for printing it

MOVE.L  #3,D0       ; print the number in D1.L using trap 15

TRAP    #15

BRA     EXIT        ; exit the program

D1SMALL:

MOVE.L  #3,D0       ; print the number in D1.L using trap 15

TRAP    #15

EXIT:

MOVE.B  #9,D0

TRAP    #15         ; halt simulator

END    START        ; last line of source

*~Font name~Courier New~

*~Font size~10~

*~Tab type~1~

*~Tab size~4~