• pep/9


    (1)编写一个伪代码算法,读入三个值,输出它们的和:

    Set sum to0
    Read num1
    Set sum to sum + num1
    Read num2
    Set sum to sum + num2
    Read num3
    Set sum to sum + num3
    If (sum<0)
    Write"Error"
    Else
    Write sum

    (2)用PEP/9 机器指令实现(1)中的算法,提交测试结果截图:

    12 00 0B 00 00 00 00 00 00 00 00 31 00 09 31 00
    07 C1 00 03 61 00 07 E1 00 03 C1 00 05 60 00 01
    E1 00 05 A1 00 09 18 00 2C 12 00 0E 39 00 03 00
    zz

      

    (3)用PEP/9 汇编语言实现(1)中的算法,提交测试结果截图:

    BR main ; Branch to main program

    sum: .WORD 0x0000 ; Set up sum and initialize to zero
    counter: .WORD 0x0000 ; Set up the counter
    num: .BLOCK 2 ; Set up a twe byte block for num
    limit: .BLOCK 2 ; Set up a twe byte block for limit

    main: DECI limit,d ; Read the number of values to add up

    loop: DECI num,d ; Read a number
    LDWA sum,d ; Load the current sum into the accumulator
    ADDA num,d ; Add the number to the sum
    STWA sum,d ; Store the sum
    LDWA counter,d ; Load the counter into the accumulator
    ADDA 1,i ; Add one to the counter
    STWA counter,d ; Store the counter
    CPWA limit,d ; Compare counter and limit
    BREQ finish ; Branch to finish if conter has reached limit
    BR loop; ; Otherwise, branch to loop to read another number

    finish: DECO sum,d ; Output sum
    STOP ; Stop
    .END

  • 相关阅读:
    (31)对象的克隆
    (30)批处理文件.bat
    06.v-on的修饰符
    06.v-on参数问题
    06.2修饰符补充
    06.1v-on基础+-.
    03.data数据对象
    02.el挂载点
    02.5v-pre指令
    02.4v-text指令
  • 原文地址:https://www.cnblogs.com/gong-jie/p/13901635.html
Copyright © 2020-2023  润新知