• 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

  • 相关阅读:
    QT 双缓冲
    ubuntu 安装SVN客户端
    高并发linux内核网络参数调优
    c aes 解密
    qt 字符类型转换
    c++ ado 操作类
    Qt中将QString转换为char *或者相反
    c++ aes 加密 解密
    [转载]python编码转换遇到的非法字符的解决方法
    [转载] python异常如何全面捕获
  • 原文地址:https://www.cnblogs.com/gong-jie/p/13901635.html
Copyright © 2020-2023  润新知