Question: I need a program in easy68k that takes a string of numbers and letters and adds the numbers together. Here's what i have: START: ORG

I need a program in easy68k that takes a string of numbers and letters and adds the numbers together. Here's what i have:

START: ORG $1000 ; first instruction of program

* Put program code here

*------ Initialization ------*

CLR.B D0

LEA Array,A0

MOVE.B #ARRAY_SIZE,D2

MOVE.B #5,D3

MOVE.B 'G',0(A0)

MOVE.B 'C',1(A0)

MOVE.B #2,2(A0)

MOVE.B #6,3(A0)

MOVE.B #8,4(A0)

MOVE.B #0,5(A0)

*buffer ds.b 80*9

*prompt dc.b 'Enter a string: ',0 ; null terminated string

; Array: [5, 7, 12, 3, 8,]

*----------------------------*

LEA ARRAYMSG,A1

MOVE.B #14,D0

TRAP #15

*--- Show the whole array ---*

LEA BRACKET1,A1 ; Initialize left bracket

MOVE.B #14,D0

TRAP #15 ; Display left bracket

LOOP MOVE.B #3,D0 ; Trap task 3, display signed number from D1

MOVE.B (A0)+,D1 ; Put number from array into D1

TRAP #15 ; Display number in D1

IF.B D2 #1 THEN ; If not end of array

LEA COMMA,A1 ; Display comma

MOVE.B #14,D0

TRAP #15

ENDI

SUB.B #1,D2 ; Iteration

BNE LOOP ; Doesn't match current criteria = loop, does match = end loop

LEA BRACKET2,A1 ; Initialize right bracket

MOVE.B #14,D0

TRAP #15 ; Display right bracket

*----------------------------*

LEA NEWLINE,A1

MOVE.B #14,D0

TRAP #15

* lea prompt,A1 ; pointer to string

* move.b #13,D0 ; display prompt

* trap #15

* lea buffer,A1

* move.b #2,D0 ; read strings from keyboard into A1

* trap #15

* move.l A1,(A0,D2) ; store strings to array at index D2

*--- Addition of even indexes should be: 5, 12, 8, 11, 2 = 38

LEA EVENMSG,A1

MOVE.B #14,D0

TRAP #15

LEA ARRAY,A0

CLR D4

EVEN MOVE.B #3,D0

MOVE.B (A0),D1 ; Data in A0 copied to D1. Contents of A0 incremented by 1 Iterate by 1 - This could've been done like: MOVE.B (A1),D1

ADDA #1,A0 ; Then iterate by another 1 - This line would be ADDA #2,A1

ADD.B D1,D4 ; Add number with the previous

MOVE.B D4,D1 ; The previous number

SUB.B #1,D3 ; Iteration

BNE EVEN ; Loop

TRAP #15 ; Display the total of added numbers

*----------------------------*

LEA NEWLINE,A1

MOVE.B #14,D0

TRAP #15

* Put variables and constants here

CR EQU $0D

LF EQU $0A

ARRAY DS.B 6 ; Allocate 5 bytes for array

ARRAY_SIZE EQU *-ARRAY

ARRAYMSG DC.B 'Array: ',0

BRACKET1 DC.B '[',0

COMMA DC.B ',',0

BRACKET2 DC.B ']',CR,LF,0

EVENMSG DC.B 'Addition of values in array: ',0

NEWLINE DC.B '',CR,LF,0

END START ; last line of source

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!