0

I have been struggling on this question for some time and need require some help.

This question is based on the EASY68K simulator processor. Use the T121 Processor Instruction Set of the EASY68K simulator to answer the following questions.

Rewrite the program in Figure Q3 to include a subroutine to add a series of integers. The subroutine should perform the functions of the loop. The subroutine occupies memory space just below the main program. Use SUM as the subroutine address label.

FIGURE Q3

        ORG     $1000
START   MOVE    #$2000,A0 
        MOVE.B  #$08,D0 
        MOVE.L  #$0,D1
LOOP    ADD.B   (A0)+,D1 
        SUB.B   #$01,D0 
        BNE     LOOP 
        LSR     #$03,D1     ; Logical Shift Right by 3 places 
        MOVE.B  D1, $2050
        STOP    #$2700

Initialise and use test data: 1, 2, 3, … up to the loop counter deduced in Question 3(b). Assume the contents of all data registers are set to zero before the start of the program.

Here is my working. I'm not sure if I'm doing it right as I don't understand how to tackle this question.

     ORG     $1000
    START   MOVE    #$2000,A0 
            MOVE.B  #$08,D0 
            MOVE.L  #$0,D1  
            BSR     SUM          ;BRANCH SUMBROUTINE   
            STOP    #$2700   

    SUM     ADD.B   (A0)+,D1 
            SUB.B   #$01,D0 
            BNE     SUM 
            LSR     #$03,D1       ; Logical Shift Right by 3 places 
            MOVE.B  D1, $2050
            RTS

            ORG     $2000
   DATA     DC.B    $1,$2,$3,$4,$5,$6,$7,$8    ; Define constant.
            END     START
Atrix370
  • 33
  • 7
  • You should put code as text here and not as figures. Also, you should add `assembly`, `easy68k`, `68000` or similar keywords as tags here so that experts in that area can find this question. And welcome to stackoverflow! – rnso Aug 27 '18 at 16:57
  • thanks for the tips – Atrix370 Aug 27 '18 at 17:10
  • Looks pretty alright to me, but why did you include the "LSR" part in the subroutine? – tofro Aug 27 '18 at 20:11
  • the final lsr and store is not part of the loop and should not be in the subroutine. In addition storing to a fixed location is bad and the $2050 should be replaced with a label – vogomatix Aug 28 '18 at 06:58

1 Answers1

0

Some improvements

  • use labels instead of fixed memory addresses
  • move shift and store of result outside routine

    ORG     $1000
    START   MOVE    #DATA,A0 
            MOVE.B  #$08,D0 
            MOVE.L  #$0,D1  
            BSR     SUM           ; sum values in subroutine
            LSR     #$03,D1       ; Logical Shift Right by 3 places 
            MOVE.B  D1, RESULT
            STOP    #$2700   
    
    SUM     ADD.B   (A0)+,D1 
            SUB.B   #$01,D0 
            BNE     SUM 
            RTS
    
            ORG     $2000
    DATA    DC.B    $1,$2,$3,$4,$5,$6,$7,$8    ; Define constant.
            ORG     $2050
    RESULT  DS.B    1
            END     START
    
vogomatix
  • 4,856
  • 2
  • 23
  • 46