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

  • 相关阅读:
    C# base64编码、解码
    C#异常重试通用类Retry
    C#操作Control异步工具类
    Notepad++的Json格式化插件
    CG 标准函数库
    Unity 几种优化建议
    基于Unity的Profiler性能分析
    Time.timeScale、游戏暂停
    Lua 中的string库(字符串函数库)总结
    Lua 日志
  • 原文地址:https://www.cnblogs.com/gong-jie/p/13901635.html
Copyright © 2011-2022 走看看