Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Easy 68K or similar, Initialize an array [5, 7, 12, 3, 8, 21, 11, 1, 2, 16

ID: 3771704 • Letter: U

Question

Using Easy 68K or similar,

Initialize an array [5, 7, 12, 3, 8, 21, 11, 1, 2, 16], and do the following operations on this array. You need to use subroutine (branch) to finish this question.

1. At the beginning of your program, you need to enter a decimal number.

2. If the number that you enter is 1, display all odd numbers in the array.

3. If the number that you enter is 2, display all even numbers in the array.

4. If the number is neither 1 nor 2, please print out an error message, like “Invalid input, please input 1 or 2”.

All the data should be in “word” size (16 bits). Start your operation at memory address of 1000 and initialize the data at 1200.

Explanation / Answer

Answer :

START ORG $400

BS EQU $08
HT EQU $09
LF EQU $0A
VT EQU $0B
FF EQU $0C
CR EQU $0D

LOOP
MOVE #6,D4
MOVE #5,D5

SameLoop LEA List,A0

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

MOVE.B #4,D0   
TRAP #15

MOVE.B D1,(A0)   
MOVE.B (A0),D0
ADD.L #1,A0
MOVE.B (A0),D1

BRA NoSwap

MadeLoop LEA MSG1,A1 * Load MSG1 into A1
MOVE.B #14,D0
TRAP #15

MOVE.B #4,D0
TRAP #15

MOVE.B D1,(A0)
MOVE.B (A0),D0
ADD.L #1,A0
MOVE.B (A0),D1
CMP.L A0,D0

SUB #1,D5
CMP #0,D5   
BEQ ANS

BGE NoSwap

SUB.L #1,A0
MOVE.B D1,(A0)
ADD.L #1,A0
MOVE.B D0,(A0)

NoSwap CMP #0,A0
BNE MadeLoop
CMP #0,D5
BNE SameLoop

ANS
MOVE.B (A0),D1
MOVE #3,D0
TRAP #15
SUB #1,A0
SUB #1,D4
CMP #0,D4
BEQ ENTER
LEA MSG2,A1
Move.B #14,D0
TRAP #15
BRA ANS

BRA LOOP

ENTER LEA MSG3,A1 * Loads MSG3 into A1
MOVE.B #14,D0
TRAP #15

List DS.B 5
ListEnd DC.B 0

* Message Definitions
MSG1 DC.B 'Enter a number: ',0 * Defines MSG1
MSG2 DC.B ',',0 * Defines MSG2
MSG3 DC.B ' ',CR,LF,0 * Defines MSG3

END START

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote