1 ; Program to read, store and echo string of 20 ASCII characters and sum up any integers 2 ; Modified for Easy68K simulator - uses Easy68k trap instructions for I/O 3 ; Sum in D2 at end, display on screen 4 5 start: org $1000 6 move.w #2,d0 ; set up registers for trap instruction to read string 7 move.w nchar,d1 ; number of characters to read in d1 (80 max) 8 lea msg,a1 ; load the address of msg in a1 (must use LEA) 9 trap #15 ; do EASY68k I/O operation 10 move.w #0,d0 ; display string on screen 11 trap #15 ; do EASY68k I/O operation 12 13 ; begin processing 14 15 clr d2 ; clear the register for the sum 16 jmp enter ; enter loop at end 17 loop: move.b (a1)+,d0 ; move the character from msg array to d0 18 jsr addit ; subroutine to test and add integers 19 enter: dbra d1,loop ; subtract 1 from d1 and see if done 20 21 ; all data processed, sum in d2 - now display number on screen 22 23 move.l d2,d1 ; put result in d1 for EASY68k I/O 24 move.w #3,d0 ; display number on screen 25 trap #15 ; do EASY68k I/O operation 26 27 STOP #$2000 ; end of program 28 29 ; Subroutine addit tests ASCII characters to see if they represent numbers 30 ; and if so, adds them to the sum in d2 31 32 addit: and.b #$7F,d0 ; mask off parity bit of character 33 cmp.b #$30,d0 ; see if it is less than $30 34 blt skip ; if so, skip to return statement 35 cmp.b #$39,d0 ; see if it is greater than $39 36 bgt skip ; if so, skip to return statement 37 and.w #$000F,d0 ; get the number 38 add.w d0,d2 ; add to sum in d2 39 skip: rts ; return from subroutine 40 41 org $2000 ; data storage area 42 msg: ds.b 80 ; storage for string of ASCII characters 43 nchar: dc.w 20 ; number of characters to read 44 END START