org $3000 START * macro for printing string pstr MACRO lea \1,a1 move.l #13,d0 trap #15 ENDM ******************************************************************************* * Begin SOLUTION to midterm practice #5. ******************************************************************************* move.w #N,-(sp) pea LMSG pea MSG jsr _copy_string adda.w #10,sp tst.w d0 bne fin ; buffer is too small, skip yelling pea LMSG jsr _yell adda.w #4,sp ******************************************************************************* * End SOLUTION ******************************************************************************* pstr MSG pstr LMSG fin move.l #9,d0 ; exit trap #15 ******************************************************************************* * Implementations of functions to call _copy_string: link a6,#0 movem.l a0-a1,-(sp) move.l 8(a6),a0 ; source move.l 12(a6),a1 ; dest move.w 16(a6),d0 ; nbytes subi.w #1,d0 ; set up for dbf loop1 move.b (a0)+,(a1)+ ; copy a character dbeq d0,loop1 ; loop if the last character copied was not ; a null terminator and space remains cmp.w #-1,d0 ; encountered null terminator? beq exit1 ; if no, return -1 clr.w d0 ; yes, so return 0 exit1 movem.l (sp)+,a0-a1 unlk a6 rts _yell: move.l 4(sp),a0 ; msg loop2 move.b (a0),d0 beq exit2 ; exit if end of string cmp.b #'a',d0 bcs skip ; don't modify if below 'a' cmp.b #'z',d0 bhi skip ; or above 'z' subi.b #$20,d0 ; upper to lower move.b d0,(a0) ; modify in place skip adda.w #1,a0 bra loop2 exit2 rts * Data MSG dc.b 'Hello universe!',0 N equ 32 LMSG ds.b N end START