zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Flask学习笔记(10):钩子函数
    Flask学习笔记(8):csrf攻防
    Flask学习笔记(7):flask-migrate
    Flask学习笔记(6):flask-script
    Flask学习笔记(5):session
    Flask学习笔记(4):cookie
    Flask学习笔记(3):上传文件
    WTForm表单验证
    WINDOWS CMD命令小集
    Alembic环境配置与基本操作
  • 原文地址:https://www.cnblogs.com/gong-jie/p/13901635.html
Copyright © 2011-2022 走看看