简体   繁体   English

子例程,使用easy68K添加一系列整数

[英]Subroutine to add a series of integers using easy68K

I have been struggling on this question for some time and need require some help. 我一直在这个问题上苦苦挣扎,需要帮助。

This question is based on the EASY68K simulator processor. 该问题基于EASY68K仿真器处理器。 Use the T121 Processor Instruction Set of the EASY68K simulator to answer the following questions. 使用EASY68K模拟器的T121处理器指令集来回答以下问题。

Rewrite the program in Figure Q3 to include a subroutine to add a series of integers. 重写图Q3中的程序,以包含一个添加一系列整数的子例程。 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. 使用SUM作为子例程地址标签。

FIGURE Q3 图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). 初始化并使用测试数据:1、2、3,...,直到问题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

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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM