【问题标题】:Procedure to check a 16 bit value and return the parity检查 16 位值并返回奇偶校验的过程
【发布时间】:2013-04-23 13:54:38
【问题描述】:

我正在使用sms32v50 simulation tool

我需要检查一个 16 位值的奇偶校验(在 2 个寄存器中给出)。我应该得到奇数或偶数位,以 Signflag 形式返回。这应该是一个过程。

【问题讨论】:

    标签: assembly cpu-registers


    【解决方案1】:

    sms32v50 asm 语言表面上看起来很像 8086,但实际上在很多方面都不同。在这种情况下,最重要的区别是它没有奇偶校验标志,因此没有捷径。

    这就是它的样子(未经测试)

    XOR AL, BL    ; assuming AL, BL are inputs
    PUSH AL
    POP BL
    SHL BL
    SHL BL
    SHL BL
    SHL BL
    XOR AL, BL
    PUSH AL
    POP BL
    SHL BL
    SHL BL
    XOR AL, BL
    PUSH AL
    POP BL
    SHL BL
    XOR AL, BL
    ; parity is now in sign flag (and the sign bit of AL)
    

    奇偶校验计算只是“对所有位进行异或”。这里的想法是可以重新分配这样的 xor 以使其更加并行。另一种方式,并行执行较少,可能如下所示:(未测试)

    XOR AL, BL
    MOV CL, 8
    _looptop:
    PUSH AL
    POP BL
    SHL BL
    XOR AL, BL
    SUB CL, 1
    JNZ _looptop
    

    或者使用查找表:(未测试)

    JMP code
    DB 0
    DB -1
    DB -1
    DB 0
    DB -1
    DB 0
    DB 0
    DB -1
    DB -1
    DB 0
    DB 0
    DB -1
    DB 0
    DB -1
    DB -1
    DB 0
    code:
    XOR AL, BL
    PUSH AL
    POP BL
    SHR BL
    SHR BL
    SHR BL
    SHR BL
    XOR AL, BL
    AND AL, 15
    ADD AL, 2   ; this 2 here assumes that the JMP to code is at 0,
                ; so you may need to add more to it
    MOV AL, [AL]
    OR AL, AL ; this is just to update the sign flag
    

    【讨论】:

      【解决方案2】:

      这是完整的工作代码,非常感谢 harold!他几乎完成了所有的工作!

      -----------------------
      
      MOV AL,03   ; register a, 1. part of input
      MOV BL,03   ; register b, 2. part of input
      
      ; --------------
      ; For visual control, saving the inputs (temporary)
      ; --------------
      PUSH AL
      POP CL
      PUSH BL
      POP DL
      
      ; --------------
      ; Paritytest
      ; --------------
      XOR AL, BL  ; compare exclusive OR the both registers
      PUSH AL     ; A save temporary
      POP BL      ; A is taken back in B
      SHL BL      ; B is moved to the left, MSB get lost
      SHL BL      ; B is moved to the left, MSB get lost
      SHL BL      ; B is moved to the left, MSB get lost
      SHL BL      ; B is moved to the left, MSB get lost
      XOR AL, BL  ; compare exclusive OR the both regsiters
      PUSH AL     ; A temporary saved
      POP BL      ; A is taken in B
      SHL BL      ; B is moved to the left, MSB get lost
      SHL BL      ; B is moved to the left, MSB get lost
      XOR AL, BL  ; vergleiche exklusive ODER die beiden register
      PUSH AL     ; A zwischenspeichern
      POP BL      ; A wird in B zurueckgeholt
      SHL BL      ; B wird nach links geschoben, MSB geht absichtlich verloren
      XOR AL, BL  ; signflag is now set, if odd.
      
      END
      

      【讨论】:

      • 谢谢阿基。我现在在大学里,想纠正它,谢谢你为我做编码部分。我已经将 cmets 翻译成英文(我希望或多或少可以理解)。问候 PS:我写道,大部分来自 harold。我只是在开头和结尾添加了一些代码。 :) 就是这样。
      • 您应该接受harold 的 回答——如有必要,建议对他进行修改。 (而且我认为目前没有任何必要——注释每一行通常只有在解释 SIMD 寄存器中非常复杂的数据流时才有用)
      猜你喜欢
      • 2011-12-08
      • 1970-01-01
      • 2019-03-08
      • 2015-06-29
      • 2014-03-04
      • 2015-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多